小弟初学VB!
我想查询两个日期之间的记录,在VB应该怎么做,SQL语句怎么写?

解决方案 »

  1.   

    Access:
    Select * From YourTable Where DateField Between #2004-10-11# And #2004-12-12#SQLServer:
    Select * From YourTable Where DateField Between '2004-10-11' And '2004-12-12'
      

  2.   

    用Between  And 就可以了,
    记得在ACCESS要用##括住日期
    在SQL SERVER 中用‘’括住日期
      

  3.   

    'vb、SQLServer的写法:Option Explicit
    Public mConnString As StringPrivate Sub Command1_Click()
        Dim mRst As New ADODB.Recordset
            mRst.CursorLocation = adUseClient
            mRst.Open "Select * From 表111 Where 收费日期 Between '" & DTPicker1.Value & "' And '" & DTPicker2.Value & "'", mConnString, adOpenStatic, adLockOptimistic, adCmdText
            MsgBox mRst.Fields(0)
    End SubPrivate Sub Form_Load()
        mConnString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=test;Data Source=server"
    End Sub