以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  请教在窗口中如何用In关键字  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=12765)

--  作者:chengzhang
--  发布时间:2011/9/14 10:42:00
--  请教在窗口中如何用In关键字

im dt2 As DataTable
        Dim dr2 As DataRow
        cmd.CommandText = "select gID from {gradeInfo} where gradeName = \'" & e.Form.Controls("cbcgInfo").value.trim() & "\'"
        dt = cmd.ExecuteReader()
        dr = dt.DataRows(0)
        cmd.CommandText = "select cID from {classInfo} where gID = " & dr("gID")
        dt2 = cmd.ExecuteReader()
        \'dr2 = dt2.DataCols
        MessageBox.Show(dt2.DataCols("cID").Tostring)
        Tables("档案信息_studentInfo").Filter = " 班级 in  条件

怎么用IN关键字,如何根据查询的cID的值作条件


--  作者:狐狸爸爸
--  发布时间:2011/9/14 11:12:00
--  

没有表测试,只能大概给个代码,请自行调整,如果班级是整数型,记得不用单引号。

 

Dim dt2 As DataTable
Dim dr2 As DataRow
Dim bjs As String
cmd.CommandText = "select gID from {gradeInfo} where gradeName = \'" & e.Form.Controls("cbcgInfo").value.trim() & "\'"
dt = cmd.ExecuteReader()
dr = dt.DataRows(0)
cmd.CommandText = "select cID from {classInfo} where gID = " & dr("gID")
dt2 = cmd.ExecuteReader()
For Each  dr As DataRow In dt2.DataRows
  bjs = bjs & "\'" & dr("班级") & "\',"
Next
bjs = bjs.Trim(","c)
Tables("档案信息_studentInfo").Filter = " 班级 in (" & bjs & ")"


--  作者:chengzhang
--  发布时间:2011/9/14 11:42:00
--  

谢谢!老大

我会调整了