VB+Access,使用DAO连接。现表里有一字符型字段strDate,保存日期数据。现如何在VB中写查询语句,具体请进入。。。

tangjichuan 2006-02-16 09:12:53
如题,条件是字段strDate中的时间和VB中传入的时间字符串比较查询出数据?该怎么写?
如:
daoDB_Local.OpenRecordset("select intYear,bytPeriod from operator where strDate <= " + strRegDate + " and strDate >= " + strRegDate)
其中strRegDate为传入的时间字符串。
快点啊,谢谢!
我没有多少分了,只能给这么多了!
...全文
128 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lgs666 2006-02-19
  • 打赏
  • 举报
回复
日期用" # "号标识.
"select intYear,bytPeriod from operator where strDate >= #" & strRegDate & "#"
ZOU_SEAFARER 2006-02-17
  • 打赏
  • 举报
回复
使用 strDate between ... and ...
tangjichuan 2006-02-17
  • 打赏
  • 举报
回复
字段strDate为string字符型。那样写结果是正确的吗?
faysky2 2006-02-16
  • 打赏
  • 举报
回复
得到strDate大于strRegDate的记录:
daoDB_Local.OpenRecordset("select intYear,bytPeriod from operator where strDate >= '" & strRegDate & "'")

得到strDate小于strRegDate的记录:

daoDB_Local.OpenRecordset("select intYear,bytPeriod from operator where strDate <= '" & strRegDate & "'")
faysky2 2006-02-16
  • 打赏
  • 举报
回复
查询语句少了几个单引号:

daoDB_Local.OpenRecordset("select intYear,bytPeriod from operator where strDate <= '" & strRegDate & "' and strDate >= '" & strRegDate & "'")

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧