ASP连接字符串后,查询数据库不能识别,解决后再加20分

来源:百度知道 编辑:UC知道 时间:2024/06/20 02:44:22
我用if request("D1")<> "--" then
x=x & "年='"&request("D1")&"'"
if request("D2")<> "--" then
x=x & " and 月='"&request("D2")&"'"
if request("D3")<> "--" then
x=x & " and 日='"&request("D3")&"'"
end if
end if
end if
判断年月日是否为"--",例如D1这个框是2009,D2是--,D3是--,那么将查询一年的数据,如果D1是2009,D2是2,D3是--那么就查询2009年2月的数据,类推.最后用select ...where x查询SQL数据库出错.识别不到x,请高手帮忙看看哪错了啊
就是x变量出问题了,我尝试直接用年月日查询都能正常使用,年月日,是三个字段,我没有用到日期类型

你有没有设定这些条件为空时的默认值
在SQL语句里你的书写格式是对的吗?
能把你的SQL发出来看下
这样很难看出是哪里错了
我估计应该是X这个变量有问题
你去找找如果用时间作为条件来查询的话格式是怎样的

试试这样写吧
sql="select...where"
if request("D1")<> "--" then
sql=sql&" 年='"&request("D1")&"'"
if request("D2")<> "--" then
sql=sql&" and 月='"&request("D2")&"'"
if request("D3")<> "--" then
sql=sql&" and 日='"&request("D3")&"'"
end if
end if
else
sql=replace(sql,"where","")
end if
里面的空格不能去掉