日期:2014-05-17  浏览次数:20870 次

asp中数据库连问题 Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e21'ODBC 驱动程序不支持
VBScript code
<%
sqlstr="select top 7 newid,newstitle,sender,senddate,itemid,isnew,isred,visitednum"
sqlstr=sqlstr & "from scnews where itemid=2 and ishidden=0 order by newsid desc"
 set conn=server.CreateObject("adodb.connection")
 conn.open "driver={SQL Server};server=.;database=db_hdcq;uid=sa;pwd=880312;"
 set rs=server.createobject("adodb.recordset")
  rs.open sqlstr,conn,1,1
  outnum=0
  Response.Write "< table width=220 border= 0 align = center  cellpadding = 0 cellspacing = 0 style='line-height:12pt'>"
  Response.Write "<tr><td height=3 colspan=2></td></tr>"
  do while not rs.eof
   Response.Write"<tr><td height=1 colspan=2 ></td></tr>"
   Response.Write "<tr><td widh=15  height=21 align=center></td>"
   if len(rs("newstitle"))>13 then
    Response.Write"<td width=205 heigth=21>"
    response.write"<a class='news' href='/show.asp? newsid=" & rs("newsid") & "'target='_blank' title='标题:"& rs("newstitle") & chr(13) & chr(10)&"发布时间:"& rs("senddate") & chr(13)&chr(10) &"阅读次数:" & rs("visitednum") &"'>"
    else
    response.write"<td width=205 height=21>"
    response.write "<a class = 'news ' href='/show,asp? newsid =" & rs("newsid") & "' target='_blank' title='发布时间:"& rs("senddate") &chr(13)&chr(10) &"阅读次数:"& rs("visitednum") &"'>"
    end if
    if rs("isred")=1 then response.wirte"<font color='#AA0000'>"
    if len(rs("newstitle"))>13 then
     response.write left(rs("newstitle"),13) & "...."
     else
     response.write rs("newstitle")
     end if
     if rs("isred")=1 then response.wirte"<font>"
     response.write"</a>"
     if rs("isnews")=1 then
     response.write"<img src='images/new.gif' width=28 heigth=11>"
     elseif datediff("d",cdate(rs("senddate")),date)<=2 then
     response.write"<img src='images/new.gif' width=28 heigth=11>"
     end if
     response.write"</td></tr>"
     rs.movenext
     outnum=outnum+1
     loop
     do while outnum< 7
    Response.Write"<tr><td height=1 colspan=2 backgorund='images/newsdotline,jep'></td></tr>"
    Response.Write"<tr><td width=15 height=21 >&nbsp;</td><td width=205 heigth=21>&nbsp;</td></tr>"
    outnum=outnum+1
    loop
    Response.Write"<tr><td height=1 colspan=2 backgorund='images/newsdotline,jep'></td></tr>"
    response.write"</table>"
    rs.close
    set rs=nothing
    %>


------解决方案--------------------
sqlstr="select top 7 newid,newstitle,sender,senddate,itemid,isnew,isred,visitednum"
sqlstr=sqlstr & "from scnews where itemid=2 and ishidden=0 order by newsid desc"
问题出在order by,第一行中没有newsid,所以正确的应该为
sqlstr="select top 7 newid,newstitle,sender,senddate,itemid,isnew,isred,visitednum"
sqlstr=sqlstr & "from scnews where itemid=2 and ishidden=0 order by newid desc"