菜鸟问题:select语句中时间查询{时间= '" & CStr(Text2.Text) & "'"}。是吗??急

lzx123 2003-05-08 05:35:58
If (Combo1.Text = "科研项目情况表") Then
selectstr = "select * from 科研项目情况表 WHERE 项目名称 ='" & Text1.Text & "' and 时间= '" & CStr(Text2.Text) & "'"
rsControlsXM.Open selectstr, cnControls, adOpenKeyset, adLockOptimistic
Set DataGrid1.DataSource = rsControlsXM
Form3.SSTab1.Tab = 0

End If
...全文
50 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
gzqreder 2003-05-09
  • 打赏
  • 举报
回复
selectstr = "select * from 科研项目情况表 WHERE 项目名称 ='" & Text1.Text & "' and 时间= #" & CStr(Text2.Text) & "#"
Sql语句中查询时间时必须要用“#……#”括起来的
cbzdream 2003-05-09
  • 打赏
  • 举报
回复
可以呀。不知你是什麽错误?
lzx123 2003-05-09
  • 打赏
  • 举报
回复
谢谢楼上的各位,我执行的时候:

selectstr = "select * from 科研项目情况表 WHERE 项目名称 ='1' or 时间= ## "
rsControlsXM.Open selectstr, cnControls, adOpenKeyset, adLockOptimistic

也就是text1.text=1 ,text2.text=空,我想查询是或者的时候怎么老提示错误呢?where里面不能用or连接??
饮水需思源 2003-05-09
  • 打赏
  • 举报
回复
数据库为access:
  selectstr = "select * from 科研项目情况表 WHERE 项目名称 ='" & Text1.Text & "' and 时间= # " & format(Text2.Text,"yyyy-mm-dd") & " # "

数据库为sql:
selectstr = "select * from 科研项目情况表 WHERE 项目名称 ='" & Text1.Text & "' and 时间= '" & format(Text2.Text,"yyyy-mm-dd") & "'"

axiulisa 2003-05-09
  • 打赏
  • 举报
回复
Sql语句中查询时间时必须要用“#……#”括起来的。
spland 2003-05-08
  • 打赏
  • 举报
回复
SQL的話
selectstr = "select * from 科研项目情况表 WHERE 项目名称 ='" & Text1.Text & "' and 时间= CAST '" & Text2.Text & "' AS DATETIME "
spland 2003-05-08
  • 打赏
  • 举报
回复
selectstr = "select * from 科研项目情况表 WHERE 项目名称 ='" & Text1.Text & "' and 时间= #" & CStr(Text2.Text) & "#"
mathsword 2003-05-08
  • 打赏
  • 举报
回复
up,waiting!
dragon525 2003-05-08
  • 打赏
  • 举报
回复
selectstr = "select * from 科研项目情况表 WHERE 项目名称 ='" & Text1.Text & "' and 时间= #" & CStr(Text2.Text) & "#"
试试!
lzx123 2003-05-08
  • 打赏
  • 举报
回复
我好象老是时间不匹配哦!!!高手是怎么回事情 ?

1,216

社区成员

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

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