VB中SQL语句中的变量的格式都怎么写?

realwhs 2003-04-02 09:17:55
比如:combo1[field_name],combo2[fields(i)_value], data1[数据库access97]
data1.recordsource=sql
sql="select * from table1 where"combo1.text & "=" & combo2.text
这句是错误的,请问正确的怎样写呢?
是不是和field_name,field(i)_value的数据类型有关呢?那怎样才能写对呢?
差不多常用的 整数,日期,文本 类型的都怎样写啊?

多谢先.
...全文
195 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
marcosong 2003-04-02
  • 打赏
  • 举报
回复
select * from table1 where combo1.text='" & combo2.text & "'"
cbr7619 2003-04-02
  • 打赏
  • 举报
回复
up吧
linfuyong 2003-04-02
  • 打赏
  • 举报
回复
对于以下几种字段
"select * from table1 where 时间字段=#" & date & "# and 字符字段='" & combo1.text & "' and 数字字段=" & 12
adonet 2003-04-02
  • 打赏
  • 举报
回复
首先sql语法错误应该
sql="select * from table1 where 字段名 = '" & combo2.text & "'"
combo1.text & "=" & combo2.text这句代码不能形成查询条件,应该用相应的字段名来和变量
进行比较
Cooly 2003-04-02
  • 打赏
  • 举报
回复
Really?
你用的是SQL Server or Oracle or Sybase?
jeansure 2003-04-02
  • 打赏
  • 举报
回复
我可以肯定是不会报错的
因为我用的很多地方都可以
chenyu5188 2003-04-02
  • 打赏
  • 举报
回复
啊~!!楼上的各位说的都很全面都很好,没有话说了。UP
Cooly 2003-04-02
  • 打赏
  • 举报
回复
不可以,如果字段是数字型,那么使用单引号汇报错!
jeansure 2003-04-02
  • 打赏
  • 举报
回复
其实不管是什么类型的,全部当成是字符型的都可以用的,下面的比较通用
sql="select * from table1 where '" & combo1.text & "'='" & combo2.text & "'"
TNT1900 2003-04-02
  • 打赏
  • 举报
回复
前面应该是:
sql="select * from table1 where " & combo1.text & "="
后面的因字段类型不同而不同:
1)数字:sql="select * from table1 where " & combo1.text & "=" & combo2.text
更准确点:
sql="select * from table1 where " & combo1.text & "=" & Cint(Val(combo2.text))

sql="select * from table1 where " & combo1.text & "=" & Clng(Val(combo2.text))
2)字符:sql="select * from table1 where " & combo1.text & "=" & "'" & combo2.text & "'"
3)日期等:请参见 DB 帮助。
enhydraboy 2003-04-02
  • 打赏
  • 举报
回复
文本型
sql="select * from table1 where " & combo1.text & "='" & combo2.text & "'"
数字型
sql="select * from table1 where " & combo1.text & "=" & combo2.text
日期型
sql="select * from table1 where " & combo1.text & "='" & format("yyyy-M-d",combo2.text) & "'"




juzi110 2003-04-02
  • 打赏
  • 举报
回复
Combol1.text是字符型
sql="select * from tablel1 where " & combol1.text & "='" & combol2.text & "'"
Combol1.text数字型
sql="select * from tablel1 where " & combol1.text & "=" & combol2.text
combol1.text日期型
sql="select * from tablel1 where" & combol1.text & "= #" & combol2.text & "# "
lxcc 2003-04-02
  • 打赏
  • 举报
回复
可以用select case 选择字段类型,然后按照类型再写sql语句
qiqif 2003-04-02
  • 打赏
  • 举报
回复
sql="select * from table1 where" & combo1.text & "=" & "'" & combo2.text & "'"
ketao_78 2003-04-02
  • 打赏
  • 举报
回复
俄,这样啊,字段是自己选的阿,
那就是楼上的是对的,我想错了
Cooly 2003-04-02
  • 打赏
  • 举报
回复
如果是日期型
sql="select * from table1 where " & combo1.text & "= convert(datetime," & combo2.text & ",121)"
minajo21 2003-04-02
  • 打赏
  • 举报
回复
日期,文本 类型要加单引号'
ketao_78 2003-04-02
  • 打赏
  • 举报
回复
sql="select * from table1 where combo1.text=" & combo2.text
应该是这样吧,真不知道你是如何定字段的
Cooly 2003-04-02
  • 打赏
  • 举报
回复
如果Combo1.text对应的字段是字符型
sql="select * from table1 where " & combo1.text & "='" & combo2.text & "'"
如果Combo1.text对应的字段是数字型
sql="select * from table1 where " & combo1.text & "=" & combo2.text
ketao_78 2003-04-02
  • 打赏
  • 举报
回复
combo1.text 这是个什么东西?
加载更多回复(2)

1,216

社区成员

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

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