语法错误 (操作符丢失) 在查询表达式 ''n_id'=' 中。

来源:百度知道 编辑:UC知道 时间:2024/06/23 08:26:14
代码如下:
<%
id=request("newsid")
isnum(id)
sql="select * from t_news where 'n_id'="& id &""
Set rst = Server.CreateObject("ADODB.Recordset")
rst.open sql,nconn,1,1
if rst.eof and rst.bof then
response.Write(" ")
response.End()
end if
%>
因为我对代码不是很熟悉,请大家回答的时候 把您想要告诉我的正确代码 发布到下面。谢谢啦

代码拷贝进去出现这样的错误。网址是:http://www.szmt-health.com/DisNews.asp 打开就可以看到 这个是什么原因啊?

id=request("newsid")

这里没有获取到值,也就是你的id为空,你可以输出一下试试
response.write "参数为:" & id
response.end

你的程序应该改进一下
<%
id=request("newsid")
if trim(id)="" then
response.write "没能获取到参数newsid"
response.end
else
if not isnum(id) then
response.write "错误,参数不是数字"
response.end
end if
end if

sql="select * from t_news where n_id="&id
Set rst = Server.CreateObject("ADODB.Recordset")
rst.open sql,nconn,1,1
if rst.eof and rst.bof then
response.Write(" 没有找到相关记录")
response.End()
end if
%>
上面改进后的已经是正确的了,具体参数形式是
浏览器地址应该为这种形式:
你的页面.asp?newsid=数字
比如:showNews.aspx?newsid=10
如果后面没有数字,那么,你看看你的链接是不是做错了,有数字才能获取到值,才能传递给Sql语句正确的值。