MAIN.DBF库中:
CDATE            BAR   
2003-06-15       3194
2003-06-15       3194
2004-05-17       11543
2004-05-21       11543
   .               .
   .               .
   .               .
我想选择>2003-06-15的所有记录,找高手来解决!!!!!!
程序如下:
Option Explicit
Dim strpath As String
Dim datetime As Date
Private Sub Form_Load()   strpath = "Provider=MSDASQL.1;Persist Security Info=False;DSN=main;UID=;"
   strpath = strpath + "SourceDB=D:\3000\TEST\数据1.dbc;SourceType=DBC;Exclusive=No;"
   strpath = strpath + "BackgroundFetch=Yes;Collate=Machine;"   Dim conn As New ADODB.Connection
   Dim rs As New ADODB.Recordset
   Dim sql As String
   conn.ConnectionString = strpath
   conn.Open
      Dim sqlcmd As New ADODB.Command
   sqlcmd.ActiveConnection = conn.ConnectionString
   
   
   datetime = "2003-06-15"
   sql = "select * from main where cdate>'应该怎么写啊'"      ←这边SQL语句出错
   rs.Open sql, conn, adOpenStatic, adLockReadOnly
   msgbox rs.recordcount
   rs.Close
   conn.Close
End Sub

解决方案 »

  1.   

    错误提示为:[Microsoft][ODBC Visual FoxPro Driver]Operator/operand type mismatch
      

  2.   

    datetime = "2003-06-15"
    sql = "select * from main where [cdate]>'" & datetime & "'"
      

  3.   

    如果你的表里设置cdate为日期类型,那得转换一下类型:datetime =CDate("2003-06-15")
    sql = "select * from main where [cdate]>'" & datetime & "'"
      

  4.   

    还是报错,我读的是dbf的数据库,用的foxpro驱动
      

  5.   

    错误提示为:[Microsoft][ODBC Visual FoxPro Driver]Operator/operand type mismatch
      

  6.   


    一般dbf的查询要写上.dbf,在main后面加上.dbf试试datetime =CDate("2003-06-15")
    sql = "select * from main.dbf where [cdate]>'" & datetime & "'"