2017中国中等收入标准:asp连接数据库出错问题

来源:百度文库 编辑:神马品牌网 时间:2024/05/03 11:43:35
<%
dim theid
theid=request("id")
set conn=server.CreateObject("adodb.connection")
conn.open "Provider=microsoft.jet.OLEDB.4.0;Data source="&server.MapPath("news.mdb")
set rs=server.CreateObject("adodb.recordset")
sql="select*from news where id=theid"
rs.open sql,conn,1,1(这是第9行)
%>这样写的代码调试时出错:
技术信息(用于支持人员)

错误类型:
Microsoft JET Database Engine (0x80040E10)
至少一个参数没有被指定值。
/news/display.asp, 第 9 行

theid是变量,你把它放在引号里,结果变成了sql拿数字型的id来和theid这个“在SQL中未定义的变量”做比较,当然会出问题了。



sql="select*from news where id=theid"

改成

sql="select*from news where id="&theid

这样就OK了!