VB 关于查询语句
来源:百度知道 编辑:UC知道 时间:2024/06/14 00:27:47
一个combo ,目的要把combo的值,当做查询语句的where条件
我写的是:
Dim cx As String
cx = Combo1.Text ' 这里有学生名字
Set rs = db.OpenRecordset("select age, sex from class where name=" & cx)
=======================================
总是参数不足,请问是不是连接符写错了!
我写的是:
Dim cx As String
cx = Combo1.Text ' 这里有学生名字
Set rs = db.OpenRecordset("select age, sex from class where name=" & cx)
=======================================
总是参数不足,请问是不是连接符写错了!
Set rs = db.OpenRecordset("select age, sex from class where name='" + cx + "'")
笨啊,要是条件多了这样写多麻烦
你可以先定义一个sqlString,如:
dim sqlString=“select * from table1 where 1=1”
……
加条件的时候更简单了
if text1.text<>"" then
sqlstring=sqlstring & "and 字段='" & cx &"'"
end if
多少条件都可以往后加,多方面,容易维护,也容易看懂。。。