如果有人知道如何在查询jtable中使用案例,请查看我的代码。
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
答案 0 :(得分:0)
使用您的声明声明,如下所示。
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"
答案 1 :(得分:0)
可能是@jtStartIndex和@jtEndIndex的问题。
答案 2 :(得分:0)
刚刚找到,请将.status = Convert.ToInt32(item(7))
更改为.status = item(7).ToString,
在 Jtable 中显示是完全不同的