If (Combo1.Text = "科研项目情况表") Then
   selectstr = "select * from 科研项目情况表  WHERE  项目名称 ='" & Text1.Text & "' and 时间= '" & CStr(Text2.Text) & "'"
   rsControlsXM.Open selectstr, cnControls, adOpenKeyset, adLockOptimistic
   Set DataGrid1.DataSource = rsControlsXM
   Form3.SSTab1.Tab = 0
                  
         End If

解决方案 »

  1.   

    selectstr = "select * from 科研项目情况表  WHERE  项目名称 ='" & Text1.Text & "' and 时间= #" & CStr(Text2.Text) & "#"
    试试!
      

  2.   

    selectstr = "select * from 科研项目情况表  WHERE  项目名称 ='" & Text1.Text & "' and 时间= #" & CStr(Text2.Text) & "#"
      

  3.   

    SQL的話
    selectstr = "select * from 科研项目情况表  WHERE  项目名称 ='" & Text1.Text & "' and 时间= CAST '" & Text2.Text & "' AS DATETIME "
      

  4.   

    Sql语句中查询时间时必须要用“#……#”括起来的。
      

  5.   

    数据库为access:
       selectstr = "select * from 科研项目情况表  WHERE  项目名称 ='" & Text1.Text & "' and 时间= # " & format(Text2.Text,"yyyy-mm-dd") & " # "数据库为sql:
         selectstr = "select * from 科研项目情况表  WHERE  项目名称 ='" & Text1.Text & "' and 时间= '" & format(Text2.Text,"yyyy-mm-dd") & "'"
      

  6.   

    谢谢楼上的各位,我执行的时候:selectstr = "select * from 科研项目情况表  WHERE  项目名称 ='1' or 时间= ## "
    rsControlsXM.Open selectstr, cnControls, adOpenKeyset, adLockOptimistic也就是text1.text=1 ,text2.text=空,我想查询是或者的时候怎么老提示错误呢?where里面不能用or连接??
      

  7.   

    selectstr = "select * from 科研项目情况表  WHERE  项目名称 ='" & Text1.Text & "' and 时间= #" & CStr(Text2.Text) & "#"
    Sql语句中查询时间时必须要用“#……#”括起来的