Search code examples
sqlvb.netjquery-jtable

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


If anyone knows how to use case in query for jtable, pls take a look my code.

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 ; "

if i use like this, it is working:

Dim batch_status As String = "status"

but with case, not.

whats problem here?

another part of code:

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

Solution

  • Just found, change .status = Convert.ToInt32(item(7)) to .status = item(7).ToString,

    displaying in Jtable is quite different