我想实现点击command7时显示表 柜子操作记录 中字段 取物时间 为空的记录
Private Sub Command7_Click()
Dim sqlstring As String
sqlstring = "select 取物时间 from 柜子操作记录 where 取物时间=''"
Data1.RecordSource = sqlstring
Data1.Refresh
end sub
运行时报错信息为:数据类型与标准表达不匹配(取物时间为DATE/TIME类型)
请问应该怎么样改才好?
另外当我把取物时间该为TEXT类型时没有报错,但是显示的记录集为空(而实际上是有的)
请问又是什么问题呢?
下面是点击command2时显示表 柜子操作记录 中全部记录,这样写的代码是正确的,为什么上面就不对呢?
Private Sub Command2_Click()
Dim sqlstring As String
sqlstring = "select *from 柜子操作记录"
Data1.RecordSource = sqlstring
Data1.Refresh
end sub

解决方案 »

  1.   

    时间为空,那么“取物时间”为DateTime类型。
    所以你不能用 where 取物时间=""
    而应该这样:sqlstring = "select 取物时间 from 柜子操作记录 where 取物时间 IS NULL"出现这个错误的原因是楼主对数据库中数据类型的不理解。
    你保存DateTime时,只能是DateTime和Null,而不能是空字串。
    你要找出所有DateTime为Null的记录时,不能用不着 = ,而要用 IS NULL
      

  2.   

    sqlstring = "select 取物时间 from 柜子操作记录 where 取物时间=''"
    改为
    sqlstring = "select 取物时间 from 柜子操作记录 where 取物时间 is null"