当前位置:编程学习 > VB >>

sql语句求助

adodc1.recordsource = " select * from 表1 where "+ combo1.list(i) +"=' "+ text1.text +" ' and "+ combo12.list(m) +"=' "+ text2.text +" ' "
请问这句有错误么?为何查询不出数据呢? --------------------编程问答-------------------- http://download.csdn.net/source/1644211 --------------------编程问答-------------------- 如果没有报错的话,需要看下表中有没有对应的记录。 --------------------编程问答-------------------- 另外最好把加号都换成 & --------------------编程问答-------------------- 没有报错,而且表中有对应的记录,所以我很困惑。 --------------------编程问答-------------------- adodc1.recordsource = " select * from 表1 where " & trim(combo1.list(i)) & "=' " & trim(text1.text) & " ' and " &  trim(combo12.list(m)) & "=' " & trim(text2.text) & " ' "

试试看

还有如果你的字段是数字的话,值不需要加单引号的 --------------------编程问答--------------------
引用楼主 wakaka121 的回复:
adodc1.recordsource = " select * from 表1 where "+ combo1.list(i) +"=' "+ text1.text +" ' and "+ combo12.list(m) +"=' "+ text2.text +" ' "
请问这句有错误么?为何查询不出数据呢?


你的数据里有前面带空格的数据啊?

adodc1.recordsource = " select * from 表1 where "+ combo1.list(i) +"=' "+ text1.text +" ' and "+ combo12.list(m) +"=' "+ text2.text +" ' " --------------------编程问答-------------------- 判断条件,前后都加了空格,注意' "包含了一个空格,另外,你写的单引号,好像也是中文的,应该是西文的单引号! --------------------编程问答--------------------
adodc1.recordsource = " select * from 表1 where " & combo1.list(i) & " = '" & text1.text & "' and " & combo12.list(m) & " = '" & text2.text & "' "
--------------------编程问答--------------------

adodc1.recordsource = " select * from 表1 where " & trim(combo1.list(i)) & "=' " & trim(text1.text) & " ' and " & trim(combo12.list(m)) & "=' " & trim(text2.text) & " ' "

--------------------编程问答-------------------- 把所有的+号换成&号

不然出现两个数字的时候就会出现两个数字的加法
认为不是连接符,而是运算符了

--------------------编程问答-------------------- 把转换的SQL语句输出,然后再分析语句是否正确。
或者把输出的SQL语句去数据库的查询分析器中执行
补充:VB ,  数据库(包含打印,安装,报表)
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,