请教各位,我想用表B的aa列的变量在外数据源里查符合aa列的所有有数据出来,但下面语句查出来的时候只有符合aa列的当前行,我应该怎样改呢?
Dim cmd As New SQLCommand
Dim st As String = Tables("表B").Current("aa")
cmd.C
cmd.CommandText = "selec ZYHGHH,BRXM00,PYRQ00 from VW_JY_JYJG00 where ZYHGHH in '" & st & "' "
Dim dt As DataTable = cmd.ExecuteReader
Tables("查询_Table1").DataSource = dt
Tables("查询_Table1").AutoSizeCols()
[此贴子已经被作者于2024/8/9 10:43:33编辑过]
表B和VW_JY_JYJG00是在同一个数据库里吗?
[此贴子已经被作者于2024/8/9 10:38:03编辑过]
如果表B数据不多,可以这样
Dim ids As String
For Each dr As DataRow In DataTables("表B").DataRows
ids = ids & ",'" & dr("aa") & "'"
Next
ids= ids.Trim(",")
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "select ZYHGHH,BRXM00,PYRQ00 from VW_JY_JYJG00 where ZYHGHH in ('" & ids & "')"
……
老师,运行后提示缺括号,检查过,都没有少,那里出错了呢?
Dim ids As String
For Each dr As DataRow In DataTables("表B").DataRows
ids = ids & ",'" & dr("aa") & "'"
Next
ids = ids.Trim(",")
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "selec ZYHGHH,BRXM00,PYRQ00 from VW_JY_JYJG00 where ZYHGHH in ('" & ids & "') "
Dim dt As DataTable = cmd.ExecuteReader
Tables("查询_Table1").DataSource = dt
Tables("查询_Table1").AutoSizeCols()
去掉单引号
cmd.CommandText = "select ZYHGHH,BRXM00,PYRQ00 from VW_JY_JYJG00 where ZYHGHH in
(" & ids & ")"