我有一个查询选择,我需要在选定的复选框列表中选择数据。有可能吗?
这是我的查询:打算使用-IN-,但我认为这不是解决方案
SELECT [scod], [ecode], [scty] ,[sonm] FROM [Z_ALI].[dbo].[M_STORE] WHERE [scod] IN ('FROMTHECHECKLIST')
我正试图这样做:
For Each row As GridViewRow In GridView1.Rows
If row.RowType = DataControlRowType.DataRow Then
Dim CheckRow As CheckBox = (TryCast(row.Cells(1).FindControl("chckSelector"), CheckBox))
If CheckRow.Checked Then
Dim scode As String = TryCast(row.Cells(2).FindControl("lblsstorecode"), Label).Text
Dim sql As String = "SELECT [scod], [ecode], [scty] ,[sonm] FROM [Z_ALI].[dbo].[M_STORE] WHERE [scod] IN ('+scode+')"
Using cmd As New SqlCommand(sql)
Using dtViewing As Data.DataTable = code.GetData(cmd, "NSP", code.HRIS, "SELECT")
If code.err = String.Empty Then
GridView4.DataSource = dtViewing
GridView4.DataBind()
Else
code.setStatus(code.err, Me.Page, "")
End If
End Using
End Using
End If
End If
Next
例如,这是从复选框列表中选择的列表
Checklist
-|351530928006|
0|351530928007|
0|351530928008|
0|351530928009|
-|3515309280010|
zero is the selected
- is not selected
是否可以从查询中获取或迭代所有列表。
答案 0 :(得分:0)
SELECT scod,ecode,scty,sonm
FROM M_STORE
WHERE scod IN (Checklist(0), Checklist(1), Checklist(2)...)
或将您的清单放在sql表中,然后执行此操作
SELECT scod,ecode,scty,sonm
FROM M_STORE
WHERE scod IN (SELECT scod FROM ChecklistTable)