如何做时间段查询? 谢谢先~1
最好是能稍微详细点~~

解决方案 »

  1.   

    Datediff是比较两个时间差多少的函数,可以比对到秒的单位,dateadd也是,具体可以查下msdn,一般时间的操作这两个就可以搞定了,你具体说说你想怎么查吧,你都不说具体,怎么具体告诉你
      

  2.   

    SQL_String = " where 日期>='" & DateToTime(DT1.Value, True) & "' and 日期<='" & DateToTime(DT2.Value, False) & "'"Public Function DateToTime(Date1 As String, First As Boolean) As Date
     If First = True Then
        DateToTime = DateAdd("D", -1, Date1) & " 23:59:59"
     Else
        DateToTime = Date1 & " 23:59:59"
     End If
    End Function
      

  3.   

    yorkness(机器猫) 我也是用的这种做的,但想让它在DateGrid中相应的按时间顺序显示出来,
    该怎么连接数据库?谢谢楼上几位了~~!
      

  4.   

    SQL_String = " where 日期>='" & DateToTime(DT1.Value, True) & "' and 日期<='" & DateToTime(DT2.Value, False) & "'"要的是日期时间段查询~~想让它在DateGrid中相应的按时间顺序显示出来,
    该怎么连接数据库?谢谢楼上几位了~~!
      

  5.   

    SQL_String = " where 日期>='" & DateToTime(DT1.Value, True) & "' and 日期<='" & DateToTime(DT2.Value, False) & "'" & " Order By 日期"
      

  6.   

    按顺序显示只要在sql语句后加order by XX或者order by XX desc在recordset里面就已经帮你排序了,不用在程序里面排的
      

  7.   

    我实在是做不好了,
    麻烦各位写的详细点好不?我就想做一简单的两个日期段查询,然后想让结果直接在datagrid中显示出来.
    但我不知道他们几个和数据库怎么连~~.
    谢谢各位了~~!
      

  8.   

    '如果是SQL数据库:'引用ADO(Microsoft ActiveX Data Objects 2.X Library)
    Private Sub Command1_Click()
        On Error GoTo err
        Dim cn As New ADODB.Connection, rs As New ADODB.RecordSet
        '有密码的连接:
        'cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=登陆用户名;Password=登录密码;Initial Catalog=数据库名;Data Source=服务器别名/IP"
        '无密码的连接:
        cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=数据库名;Data Source=服务器别名/IP"
        cn.Open
        rs.CursorLocation=adUseClient'设置客户端游标
        rs.Open "select * from 表 ......具体的查询语句自己写上去", cn, 1, 2
        Set DataGrid1.DataSource=rs '数据显示到DataGrid
        Exit Sub
    err:
        MsgBox err.Description
    End Sub