VB数据库多查旬的问题

来源:百度知道 编辑:UC知道 时间:2024/09/22 05:24:57
我的目的是通过 具体情况来 选择字段查询 用的是ADODC+DataGrid 连接显示。但老是报错 ,请教高手 代码如下:
If fenlei1 = "" Then
strsql = strsql
Else
strsql = strsql & "and fenlei1='" & fenlei1 & "'"
End If
If fenlei2 = "" Then
strsql = strsql
Else
strsql = strsql & "and fenlei2='" & fenlei2 & "'"
End If
If fenlei3 = "" Then
strsql = strsql
Else
strsql = strsql & "and fenlei3='" & fenlei3 & "'"
End If
If fenlei4 = "" Then
strsql = strsql
Else
strsql = strsql & "and fenlei4='" & fenlei4 & "'"
End If
If fenlei5 = "" Then
strsql = strsql
Else
strsql = strsql & "and fenlei5='" & fenlei5 & "'"
End If
If strsql = "" Then
strsql = "select *

strsql = strsql & "and fenlei5='" & fenlei5 & "'"
strsql = "select * from xinxi where" & strsql

问题1、
fenlei5是不是字段名?
问题2、
"and ,and前面是否有空格?或者where"的where后面是否有空格?
问题3、
将你的这而语句链接起来是:
strsql = "select * from xinxi where and fenlei5='" & fenlei5 & "'" 姑且fenlei5是字段名并且有空格,看出问题了吗?在where的后面不能直接链接 and 运算符。
至于怎么解决,看你的程序你自己修改吧。