程序窗口上提供了3个checkbox供用户选择,当checkbox选中时,则分别将选择值定为1,2,3,如果不选择,则不做任何操作。待用户选择后,将这三个值作为查询参数传递到三个textbox中,并在数据表中找出此类型的数据。但是编译过程中出错,请帮忙看看如何将这几个控件的选择值作为查询的条件。public sub check()dim custype1,custype2,custype3 as integer
dim connection as new ADODB.connection
dim getresult as new ADODB.recordset  if checkbox1.enable = True
    custype1=1
    textbox1.text=custype1
  end if
  if checkbox2.enable =True
    custype2=2
    textbox2.text=custype2
  end if
  if checkbox3.enable = True
    custype3 = 3
    text3.text=custype3
  end ifset connection = new ADODB.connection
connection.ConnectionString = "driver={SQL Server};server=local;uid=sa;pwd=;database=test"
connection.openset getresult = new ADODB.recordset
sql = "select * from test_table where custype in ('custype1','custype2','custype3')"
getresult.open sql,connection程序可以编译执行,但是总是无法从数据表中取出记录,请大家帮忙看看到底该如何修改才能够把数据查询出来。

解决方案 »

  1.   

    sql = "select * from test_table where custype in ('" & custype1 & "','" & custype2 & "','" & custype3 & "')"  
      

  2.   

    To: cangwu_lee(小橙子) 
    好像还是不行,请帮忙看看是否还有别的方法。
    我还有一个附加条件是从两个DTPicker控件取时间的,系统可以将这条语句正确执行,并得出记录。sql=Sql = "select * from vtSalesByDealer where cdate between '" + Str(DTPicker1.Value) + "'and '" + Str(DTPicker2.Value) + "' order by cdate
      

  3.   

    dim sql as string
    sql="select * from test_table where custype in ("
    if isnumeric(me.text1.text) then sql=sql+"'"& me.text1.text &"'"
    if isnumeric(me.text2.text) then sql=sql+"'"& me.text2.text &"'"
    if isnumeric(me.text3.text) then sql=sql+"'"& me.text3.text &"'"
    sql=sql+")"
      

  4.   

    我还有一个附加条件是从两个DTPicker控件取时间的,系统可以将这条语句正确执行,并得出记录。sql=Sql = "select * from vtSalesByDealer where cdate between '" + Str(DTPicker1.Value) + "'and '" + Str(DTPicker2.Value) + "' order by cdate
    什麽意思薩?