vb.net - 在 sql 中对 jtable 使用案例 select 查询

vb.net - using case select query in sql for jtable

如果有人知道如何在jtable查询中使用case,请看看我的代码。

Dim batch_status As String = " case when status = 0 then 'Created' when status = 1 then 'Scanning' when status = 2 then 'Scan Saved' end as status"

cmd.CommandText = "SELECT  * FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY " & jtSorting & "  ) AS RowNum, batch_id, batch_name, date_created, profile_id, total_page, " & batch_status & ", First_ScanID, file_id " & _
                                " FROM [ip_ent_site].[dbo].[tbl_batch] WHERE STATUS IN (0,1,2) ) AS RowConstrainedResult " & _
                            " WHERE  RowNum >= @jtStartIndex AND RowNum < @jtEndIndex ORDER BY RowNum ; "

如果我这样使用,它是有效的:

Dim batch_status As String = "status"

但是有大小写,没有。

这里有什么问题?

另一部分代码:

If dt.Rows.Count > 0 Then
    students = (From item In dt.AsEnumerable() Select New Class1 With { _
     .No = Convert.ToInt32(item(1)), _
     .batch_id = Convert.ToInt64(item(2)), _
     .batch_name = DirectCast(item(3), String), _
     .date_created = item(4).ToString, _
     .profile_id = Convert.ToInt32(item(5)), _
     .total_page = Convert.ToInt32(item(6)), _
     .status = Convert.ToInt32(item(7)), _
 .First_ScanID = Convert.ToInt32(item(8)), _
 .file_id = CheckDBNullInteger(item(9)) _
}).ToList()

End If

使用如下声明语句。

Dim batch_status As String = " case when status = 0 then ''Created'' when status = 1 then ''Scanning'' when status = 2 then ''Scan Saved'' end as status"

可能是@jtStartIndex 和@jtEndIndex 的问题。

刚找到,把.status = Convert.ToInt32(item(7))改成.status = item(7).ToString,

Jtable中显示完全不同