请教RecordSet.open方法使用问题 
Public Zf As ADODB.Connection
Public Jlj_Lsxf As ADODB.Recordset
joe as date
Jlj_Lsxf.Open "select * from xfb where xfb.date=joe", Zf   '到这个语句就出错了!
Jlj_Lsxf.Open "select * from xfb",ZF                       '这样写就不会错!请问该语句该怎样写?
joe是个日期型的,其值是这样的:"2004-11-16 14:49:00"

解决方案 »

  1.   

    你给写成 
    Jlj_Lsxf.open "select * from xfb where xfb.date="& joe,zf
      

  2.   

    这样就可以了Jlj_Lsxf.Open "select * from xfb where xfb.date=#"& joe #&"", Zf
      

  3.   

    Jlj_Lsxf.Open "select * from xfb where xfb.date=joe", Zf   '到这个语句就出错了!
    //这样把joe看做DB的一个字段名称了!
    改为
    Jlj_Lsxf.Open "select * from xfb where xfb.date='" & joe & "'", Zf ,1,3
      

  4.   

    还有就是这种数据是属于哪种数据类型呢?我给它赋为date类型好像说类型错误啊~大哥!
      

  5.   

    应该这样.Dim joe As Date
    joe = #11/16/2004 2:49:00 PM#Jlj_Lsxf.Open "select * from xfb where xfb.date=#"& joe #&"", Zf
      

  6.   

    这个变量f其实就是日期跟时间的结合,这样上面提供的语句是不是有错误呢?我的代码是这样的
    Public Sub Dw_lsxf(e As String, f As Date)
        Jlj_Lsxf.Open "select * from xfb where xfb.name='" & e & "'and xfb.dat=#" & f# & "", Zf    
    MsgBox Jlj_Lsxf.GetString
    End Sub
    显示"声明字符与声明的数据类型不符合"
      

  7.   

    如果是SQL server,虫子的写法没有问题,如果是ACCESS则要加##变成
    #"& joe #&""或者cdate(‘“& joe &”’)
      

  8.   

    汗!我那个是SQL Server,假如是Access就如楼上的兄弟所写的那样用 #
      

  9.   

    楼主的代码少了一个空格.Public Sub Dw_lsxf(e As String, f As Date)
        Jlj_Lsxf.Open "select * from xfb where xfb.name='" & e & "'and xfb.dat=#" & f # & "", Zf    
    MsgBox Jlj_Lsxf.GetString
    End Sub
      

  10.   

    请大哥们帮忙一下好吗?看到底是哪里错了这代码:
    Public Sub Dw_lsxf(e As String, f As Date)
        Jlj_Lsxf.Open "select * from xfb where xfb.name='" & e & "'and xfb.dat=#" & f# & "", Zf    
    MsgBox Jlj_Lsxf.GetString
    End Sub