我正在尝试在SQL语句中为列字段使用变量,但它会向我发回以下错误:
Microsoft OLE DB Provider for ODBC Drivers错误“80040e14”
[Microsoft] [ODBC文本驱动程序]查询表达式中的语法错误(缺少运算符)'='是''。
/junk/dbresults.htm,第31行
代码:
<%
Dim connectString, connect, conDB, con
connectString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DBQ=" & Server.MapPath("data")
src_abn = Request.QueryString("abn")
src_cat = Request.QueryString("cat")
set connect = Server.CreateObject("ADODB.connection")
connect.open connectString
if src_abn = "all" then
conDB = "SELECT * FROM cont.csv WHERE " & src_cat & " = 'Yes'"
else
conDB = "SELECT * FROM cont.csv WHERE ucase(abn) LIKE ucase('%"+src_abn+"%')"
end if
set con = connect.execute(conDB)
%>
答案 0 :(得分:1)
看起来src_cat
的值包含创建无效查询的空格或其他字符。尝试将该行更改为此(带括号):
conDB = "SELECT * FROM cont.csv WHERE [" & src_cat & "] = 'Yes'"
答案 1 :(得分:0)
修正了它,未声明变量。