加代码控制,用if判断后再组合sql语句,1=1 是为了接and条件,可以修改成一个必填项
'建立连接
conn=……
'指定查询条件
sql="select * from 表 where 1=1"
if 地址<>"" then
sql = sql & "and 地址='上海'"
end if
if 性别<>"" Then
sql = sql & "and 性别="男""
end if
if 性别<>"" then
sql = sql & "and 职业='工程师'"
end if
……
'执行查询
rs.open sql,conn,1,3
'循环列出查询到的纪录集字段
do while not rs.eof
……
loop
搜索条件
sql="select * from 表 where 地址='上海' or 性别="男" or 职业='工程师'"
比较好,用or
AddText request("AddText ")
SexText request("SexText ")
StrSQL ="select * from 表 where
StrSQL = StrSQL & " address like '%" & AddText &"%' "
StrSQL = StrSQL & "and sex like '%" & SexText &"%' "
...
sql="select * from 表 where 职业='工程师'"
if 性别<>"" then
sql=sql&" and 性别='"&request("性别")&"'"
end if
if 地址<>"" then
sql=sql&" and 地址='"&request("地址")&"'"
end if