Dim msg
msg = Trim(InputBox("请输入" + Combo2.Text, "信息查询"))
If Combo2.Text = "违章日期" Then
msg = "select 车号,违章内容,扣除分数,执法人员,违章来源,处罚通知书编号,违章日期, 处理日期 from TSB where 违章日期 like '" & msg & "'"
End If
If Combo2.Text = "处理日期" Then
msg = "select 车号,违章内容,扣除分数,执法人员,违章来源,处罚通知书编号,违章日期, 处理日期 from TSB where 处理日期 like '" & msg & "'"
End If
DataGrid1.RecordSelectors = True
Adodc1.RecordSource = msg
Adodc1.Refresh
日期在datagrid中显示的格式为xxxx-xx-xx(2006-5-6).
我想查询日期,但在InputBox中输入2006-5-6后,查询不到,在datagrid中看不到...
如何解决!!!!!!

解决方案 »

  1.   

    日期类型不能用like
    只能用 between
    或者 "datediff(day,处理日期,'" & msg & "')=0"
      

  2.   

    format 一下
    另外,数据库里面 DateTime类型包括日期和时间,查询的时候,只输入日期部分,又使用“=”操作符。所以,查不到。
    "(违章日期>='" & msn & " 0:0:0' or 违章日期<='" & msg " 23:59:59' )"
      

  3.   

    用DateDiffDim msg
    msg = Trim(InputBox("请输入" + Combo2.Text, "信息查询"))
    If Combo2.Text = "违章日期" Then
    msg = "select 车号,违章内容,扣除分数,执法人员,违章来源,处罚通知书编号,违章日期, 处理日期 from TSB where DateDiff(dd, 违章日期, '" & msg & "') = 0"
    End If
    If Combo2.Text = "处理日期" Then
    msg = "select 车号,违章内容,扣除分数,执法人员,违章来源,处罚通知书编号,违章日期, 处理日期 from TSB where DateDiff(dd, 处理日期, '" & msg & "') = 0"
    End If
    DataGrid1.RecordSelectors = True
    Adodc1.RecordSource = msg
    Adodc1.Refresh
      

  4.   

    或者轉換下Dim msg
    msg = Trim(InputBox("请输入" + Combo2.Text, "信息查询"))
    If Combo2.Text = "违章日期" Then
    msg = "select 车号,违章内容,扣除分数,执法人员,违章来源,处罚通知书编号,违章日期, 处理日期 from TSB where Convert(Varchar, 违章日期, 120) like '%" & msg & "%'"
    End If
    If Combo2.Text = "处理日期" Then
    msg = "select 车号,违章内容,扣除分数,执法人员,违章来源,处罚通知书编号,违章日期, 处理日期 from TSB where Convert(Varchar, 处理日期, 120) like '%" & msg & "%'"
    End If
    DataGrid1.RecordSelectors = True
    Adodc1.RecordSource = msg
    Adodc1.Refresh
    查詢時必須輸入這樣的格式2006-05-06
      

  5.   

    用cdbl转换下
    where [违章日期]=cdbl(now)
      

  6.   

    数据库为SQL:" select * from tablename where 日期字段='"& 日期变量 &"'"
    数据库为ACCESS:"select * from tablename where 日期字段=#"& 日期变量 &"#"