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>请输入查询条件 </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>