| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 577 人关注过本帖
标题:sql语句应该如何写才不会报错
只看楼主 加入收藏
jingjing316
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:293
专家分:541
注 册:2009-8-11
结帖率:92.31%
收藏
已结贴  问题点数:20 回复次数:3 
sql语句应该如何写才不会报错
图片附件: 游客没有浏览图片的权限,请 登录注册

使用的是 sql server 2003
代码如下,主要起个查询功能
 <%@language=vbscript%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>计算机统计表</title>
<style type="text/css">
.warp_table {border-collapse:collapse; width:550px; border:1px solid #4d9ab0}
.warp_table td {border:1px solid #4d9ab0}
</style>
<script language="javascript"><!--
function senfe(o,a,b,c,d){
 var t=document.getElementById(o).getElementsByTagName("tr");
 for(var i=0;i<t.length;i++){
  t[i].style.backgroundColor=(t[i].sectionRowIndex%2==0)?a:b;
  t[i].onclick=function(){
   if(this.x!="1"){
    this.x="1";
    this.style.backgroundColor=d;
   }else{
    this.x="0";
    this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
   }
  }
  t[i].onmouseover=function(){
   if(this.x!="1")this.style.backgroundColor=c;
  }
  t[i].onmouseout=function(){
   if(this.x!="1")this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
  }
 }
}


--></script>
</head>
<body>
<table border=0 cellspacing="1" bgcolor="#ffcb7d"  background="images/admin_bg_1.gif"  align=center>
<tr bgcolor="#99CCFF"><td>请输入查询条件&nbsp;&nbsp;</td>
<form action="cx0.asp" id=form1 name=form1>
<td>
<select  size="1" name="runstatus">
<option value="" selected >        </option>   
         <option value="1" >开机</option>
      <option value="0"> 关机</option>
<input type="submit" value="提交" name="B1" class="buttonface">

</td></form></tr>
</table>
<%
   const MaxPerPage=30
   dim sql
   dim rs
   dim totalPut   
   dim CurrentPage
   dim TotalPages
  Dim cnn,strcnn
 
 sql=""
runstatus=request("runstatus")
'response.write runstatus
set cnn=server.createobject("adodb.connection")
strcnn="Provider=SQLOLEDB.1;User Id=xxzx;Password=zmgl2009;Initial Catalog=vrveis;Data Source=10.141.136.12,1433;Persist Security Info=True;Connect Timeout=100"
cnn.open strcnn

set rs =server.CreateObject("adodb.recordset")
if runstatus<>"" then

sql="select officename,username,cputype,ipaddres,macaddress,memory,disksize,runstatus,registered from  device  where runstatus='&runstatus&' order by officename"   报错行

else

sql="select officename,username,cputype,ipaddres,macaddress,memory,disksize,runstatus,registered from device order by officename"
end if
rs.open sql,cnn,1,1
rs.MoveFirst
rs.pagesize=MaxPerPage
howmanyfields=rs.Fields.Count-1
If trim(Request("Page"))<>"" then
    CurrentPage= CLng(request("Page"))
    If CurrentPage> rs.PageCount then
        CurrentPage = rs.PageCount
    End If
Else
    CurrentPage= 1
End If
i=CurrentPage+(CurrentPage-1)*29
totalPut=rs.recordcount
    if CurrentPage<>1 then
        if (currentPage-1)*MaxPerPage<totalPut then
            rs.move(currentPage-1)*MaxPerPage
            dim bookmark
            bookmark=rs.bookmark
        end if
    end if
    dim n,k
    if (totalPut mod MaxPerPage)=0 then  
        n= totalPut \ MaxPerPage
    else  
        n= totalPut \ MaxPerPage + 1  
    end if%>
    </FONT></FONT></P>
<P>页码<%=currentpage%>/<%=n%> ,共<%=rs.recordcount%> 纪录
    <%    k=currentPage
        if k<>1 then
            response.write "[<b>"+"<a href='cx0.asp?page=1'>首页</a></b>] "
            response.write "[<b>"+"<a href='cx0.asp?page="+cstr(k-1)+"'>上一页</a></b>] "
        else
            Response.Write "[首页] [上一页]"
        end if
        if k<>n then
            response.write "[<b>"+"<a href='cx0.asp?page="+cstr(k+1)+"'>下一页</a></b>] "
            response.write "[<b>"+"<a href='cx0.asp?page="+cstr(n)+"'>尾页</a></b>] "
        else
            Response.Write "[下一页] [尾页]"
        end if
    %>

<table border="1" cellspacing="1" class="warp_table" id="changecolor" width="100%">
<tr >
<td  width="10">序号</td>
<td width="150">单位名称</td>
<td width="100">用户姓名</td>
<td width="100">ip地址</td>
<td width="100">mac地址</td>
<td width="200">cpu型号</td>
<td width="100">内存大小</td>
<td width="100">硬盘大小</td>
<td>运行状态</td>
<td>注册状态</td>
</tr>
<%i1=0
do while not rs.eof and i1<maxperpage%>
<tr>
<td><%=i%></td>
<td><%=rs("officename")%></td>
<td><%=rs("username")%></td>
<td><%=rs("ipaddres")%></td>
<td><%=rs("macaddress")%></td>
<td width="200"><%=rs("cputype")%></td>
<td><%=rs("memory")%>M</td>
<td><%=rs("disksize")%>M</td>

<td><% if rs("runstatus")="1" then response.write"开机" end if %><% if rs("runstatus")="0" then response.write"关机" end if  %>
<td><% if rs("registered")="1" then response.write"注册" end if %><% if rs("registered")="0" then response.write"未注册" end if  %>
</tr>
<%
    i=i+1
i1=i1+1
rs.movenext
loop
rs.close
set rs=nothing
%>
</table>
<script language="javascript"><!--
//senfe("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景");
senfe("changecolor","#f8fbfc","#e5f1f4","#ecfbd4","#bce774");
--></script>

</body>
</html>
搜索更多相关主题的帖子: 会报 sql 语句 
2010-11-29 11:03
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:10 
runstatus
这个字段是什么数据类型的?
2010-11-29 11:34
wangjy500
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:13
帖 子:457
专家分:2569
注 册:2010-7-11
收藏
得分:10 
sql="select officename,username,cputype,ipaddres,macaddress,memory,disksize,runstatus,registered from  device  where runstatus='&runstatus&' order by officename"
---------------->
sql="select officename,username,cputype,ipaddres,macaddress,memory,disksize,runstatus,registered from  device  where runstatus='"&runstatus&"' order by officename"

QQ:63572063
2010-11-29 12:32
jingjing316
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:293
专家分:541
注 册:2009-8-11
收藏
得分:0 
runstatus是tinyint类型
改成这个runstatus='"&runstatus&"'就不报错了
2010-11-29 14:11
快速回复:sql语句应该如何写才不会报错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029115 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved