首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

跪求高手! 语法异常 (操作符丢失) 在查询表达式 'id=' 中

2012-03-15 
跪求高手! 语法错误 (操作符丢失) 在查询表达式 id 中我在作一个关于新闻系统时出现以下错误 语法错误(

跪求高手! 语法错误 (操作符丢失) 在查询表达式 'id=' 中
我在作一个关于新闻系统时出现以下错误 语法错误   (操作符丢失)   在查询表达式   'id= '   中,在页面中左边是新闻标题,右边想显示内容,以下是程序代码,敬请高手指点,万分感谢!!!!

数据库连接程序conn.asp如下:
<%

set   conn=Server.Createobject( "ADODB.Connection ")  
connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data   Source= "   &   Server.MapPath( "jmsj.mdb ")
conn.open   connstr
%>  

页面程序gg.asp如下:
<!--#include   file= "conn.asp "-->
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
</head>
<body>
<%


str= "select   *   from   gsnews   order   by   data   desc "
set   rs=server.createobject( "adodb.recordset ")
rs.open   str,conn
if   not   rs.bof   and   not   rs.eof   then

  %>
<table   width= "760 "   height= "600 "   border= "1 ">
    <tr>
        <td> <table   width= "350 "   height= "300 "   border= "1 ">
            <tr>
                <td> <font   size= "2 ">
<%   do   while   not   rs.eof   %>
<br>
<a   href= "gsnews.asp?id= <%=rs( "id ")%> "> <%=rs( "title ")%> </a>
<br>
<%
rs.movenext
loop
end   if

%>



</font>

</font> </td>
            </tr>
        </table> </td>
        <td>
<%
dim   id
id=request.QueryString( "id ")
strsql= "select   *   from   gsnews   where   id= "   &   id
set   rs=conn.execute(strsql)
%>
<table   width= "410 "   height= "400 "   border= "1 ">

            <tr>
                <td> <%=rs( "title ")%> </td>
            </tr>
            <tr>
                <td> <%=rs( "content ")%> </td>
            </tr>
            <tr>
                <td> &nbsp; </td>
            </tr>
        </table> </td>
    </tr>
</table>
</body>
</html>
数据库我用的是Access,敬请指点!!


[解决办法]
你没用框架还这样传值?或者你用框架或者把 <a href= "gg.asp?id= <%=rs( "id ")%> "> <%=rs( "title ")%> </a>
------解决方案--------------------


你试着将这句代码:strsql= "select * from gsnews where id= " & id
改为这样看行不行啊!~代码如下:
strsql= "select * from gsnews where id= ' "&id& " ' "

[解决办法]
因为第一次进去的时候,没有参数id传入,所以sql出错了
建议判断下id是否存在,如下
dim id
id=request.QueryString( "id ")
if id <> " " && id <> null then
strsql= "select * from gsnews where id= " & id
set rs=conn.execute(strsql)
......
[解决办法]
<%
dim id
id=request.QueryString( "id ")
strsql= "select * from gsnews where id= " & id
set rs=conn.execute(strsql)
%>
这里面的id没有值,与前面的 <a href= "gg.asp?id= <%=rs( "id ")%> "> <%=rs( "title ")%> </a> 这里的id是没有关系的,因为两段代码在一个页面上,所以 <a href……里面的id并没有传过来.
[解决办法]
"id= ' "&字符型& " ' " "id= "&整型

热点排行