以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  赋值语法求助  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=108478)

--  作者:huhu
--  发布时间:2017/10/23 18:42:00
--  赋值语法求助
Dim result As New System.Data.DataTable
SqlDataAdapter.Fill(result)
If result.Rows.Count >= 2  and Then
Dim id_flag As String \'id_flag是列名
For Each drr As DataRow In result.Rows
  id_flag &= \'" & drr("id_flag") & "\' & "or"---------这么写肯定不对,那么应该怎么写?循环到最后一行or不要。
 Next
                    
strS ql = "sel ect * from [可用数量表]  where " & “(” & "id_flag" & ")"
End if

问题很简单,我就是希望循环result表的行,如果行数大于等于2,比如行数为3行,第一行的drr("id_flag") = 1,第二行的drr("id_flag") = 2 ,第三行的drr("id_flag")  = 3.
然后希望strsql变为下面的。
strS ql = "sel ct * from [可用数量表]  where " & “(” & id_flag = "1" or id_flag = "2" or id_flag = "3" & ")"

--  作者:ybil
--  发布时间:2017/10/23 18:55:00
--  
For Each drr As DataRow In result.Rows
  id_flag &=" Or \'"  & drr("id_flag") &  "\'"
 Next
 id_flag = id_flag.Substring(4) 
strS ql = "sel ect * from [可用数量表]  where " & “(” & "id_flag& ")"

--  作者:有点蓝
--  发布时间:2017/10/23 20:27:00
--  
Dim id_flag As String = "id_flag in ("

For Each drr As DataRow In result.Rows
    id_flag &= "\'" & drr("id_flag") & "\',"
Next
id_flag = id_flag.Trim(",") & ")"
strS ql = "sel ect * from [可用数量表]  where " & id_flag