squery.asp

来自「《动态网页设计基础教程》,胡杰,科学出版社」· ASP 代码 · 共 213 行

ASP
213
字号
<%
IF request.servervariables("Request_Method")="POST" THEN
'// If clicked ADD button then call Slogin.asp"
 if request.form("cmdaddks")="添加考生" then
    Session("EditFlag")="INSERT"
    response.redirect "Studentlogin.asp"
 end if

'//If clicked DEL then 
 if request.form("cmdDelks")="删除考生" then
    set Conn=Server.CreateObject("ADODB.Connection")
    'Conn.open session("sysDSN")
    conn.open "Driver={SQL Server};Database=testonline;Server=(local);uid=sa;pwd="
    for each item in request("Selected")
    '/To Delete all selectd Student
        conn.Execute "delete from student where TestNo='" & item & "'" ,,1
    next
    set conn=nothing
    response.redirect ("Squery.asp")
 end if

'//If clicked Update then 
 if request.form("cmdMdyks")="修改考生" then
 Dim RecordsetArray
 Dim LocalArray(100)
 
    Session("EditFlag")="MODIFY"
    set Conn=Server.CreateObject("ADODB.Connection")
    'Conn.open session("sysDSN")
    conn.open "Driver={SQL Server};Database=testonline;Server=(local);uid=sa;pwd="
    for each item in request("Selected")
        Session("TestNo")=item    
        set rs=conn.Execute ("select * from student where TestNo='" & item & "'")
        RecordArray=RS.GetRows()
        LocalArray(0)=RecordArray(0,0)
        LocalArray(1)=RecordArray(1,0)
        LocalArray(2)=RecordArray(2,0)
        LocalArray(3)=RecordArray(3,0)
        LocalArray(4)=RecordArray(4,0)
        LocalArray(5)=RecordArray(5,0)
        LocalArray(6)=RecordArray(6,0)
        LocalArray(7)=RecordArray(7,0)
        LocalArray(8)=RecordArray(8,0)
        LocalArray(9)=RecordArray(9,0)
        LocalArray(10)=RecordArray(10,0)
        LocalArray(11)=RecordArray(11,0)
        LocalArray(12)=RecordArray(12,0)
        LocalArray(13)=RecordArray(13,0)
        LocalArray(14)=RecordArray(14,0)

        session("DataArray")=LocalArray
                
        Set RS=nothing
        Response.Redirect ("Studentlogin.asp")
    next
    set conn=nothing
    response.redirect ("Squery.asp")
 end if
End if
%>
  
<%
Dim sql
Dim reccount
Dim fieldi,recordi
Dim t1,t2,t3
Dim ps,mypagesize,ys,mypage
Dim maxcount
              

t1=request("T1")
t2=request("T2")
t3=request("T3")

set Conn=Server.CreateObject("ADODB.Connection")
'Conn.open session("sysDSN")
conn.open "Driver={SQL Server};Database=testonline;Server=(local);uid=sa;pwd="

if t1<>"" or t2<>"" or t3<>"" then 
  sql="select * from Student where "
  if t1<>"" then
     sql=sql + "TestNO='" + t1 + "'"
  end if
  if t2<> "" then
     if t1 <> "" then
        sql = sql + " OR "
     end if
     sql=sql + "StudentID='" + t2 + "'"
  end if
  if t3 <> "" then
     if t1 <> ""  or t2 <> "" then
        sql = sql + " OR  "
     end if
     sql =sql + "StudentName='" + t3 + "'"
  end if
else
  sql="select * from Student "
end if


set rs=Server.CreateOBject("ADODB.Recordset")
rs.open sql,conn,1,2,1    

IF not rs.eof then 
   Reccount=rs.RecordCount
   Rs.PageSize=5
   ps=Rs.PageSize
   mypagesize=request.querystring("pagesize")
   if mypagesize="" then
      mypagesize=ps '//Set page size
   end if
   
   ys=rs.PageCount
   
   if ys=0 then
      mypage=reccount\ps
   else
      mypage=reccount\ps +1
   end if
   if mypage=0 then  '//To pointe first page
      mypage=request.querystring("whichpage")
   end if
   'response.redirect "Squery.asp?whichpage=" & mypage & "&pagesize=" & mypagesize
end if
%>
<html>

<head>
<link rel="stylesheet" href="comCSS.css">
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>考生信息管理</title>

<base target="_self">
<meta name="Microsoft Border" content="t, default">
</head>

<body ><!--msnavigation--><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>

<p align="left"> </p>

</td></tr><!--msnavigation--></table><!--msnavigation--><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><!--msnavigation--><td valign="top">

<form method="post">
<table border=0 cellspacing="0">
<tr>
<td><font face="华文行楷" size="4" color="#FF0000" ><b>  
考生信息列表: </b></font> [Page &nbsp;<%=mypage%>&nbsp;0f&nbsp;<%=ys%>][  记录总数:<%=Reccount%>]</td>  
</table>                             
<div align="left">  
  <table border="1" width="1260">  
    <tr Align="center">  
      <td width="184"><font color="#000080"><b>准考证号</b></font></td>  
      <td width="80"><font color="#000080"><b>学号</b></font></td>  
      <td width="55"><font color="#000080"><b>姓名</b></font></td>  
      <td width="41"><font color="#000080"><b>性别</b></font></td>  
      <td width="74"><font color="#000080"><b>出生日期</b></font></td>  
      <td width="135"><font color="#000080"><b>出生地</b></font></td>  
      <td width="144"><font color="#000080"><b>身份证号</b></font></td>  
      <td width="40"><font color="#000080"><b>民族</b></font></td>  
      <td width="120"><font color="#000080"><b>所在院系</b></font></td>  
      <td width="100"><font color="#000080"><b>班级</b></font></td>  
      <td width="77"><font color="#000080"><b>入学日期</b></font></td>  
      <td width="127"><font color="#000080"><b>考试科目</b></font></td>  
      <td width="80"><font color="#000080"><b>考试级别</b></font></td>  
      <td width="150"><font color="#000080"><b>备注</b></font></td>  
    </tr>  
    <%for recordi=1 to rs.PageSize
      if rs.Eof then Exit for
    %>  
    <tr>  
      <td width="184"><input type="checkbox" name="Selected" value="<%=rs(0) %>">  
      <a href="edit_ks.asp?which=<%=rs(0)%>&whichpage=<%=mypage%>">  
      <%=rs(0)%></a></td>  
      <td width="80"><% =rs(2) %></td>  
      <td width="55"><% =rs(3) %></td>  
      <td width="41"><% =rs(4) %></td>  
      <td width="74"><% =rs(5) %></td>  
      <td width="135"><% =rs(6) %></td>  
      <td width="144"><% =rs(7) %></td>  
      <td width="40"><% =rs(8) %></td>  
      <td width="120"><% =rs(9) %></td>  
      <td width="80"><% =rs(10) %></td>  
      <td width="77"><% =rs(11) %></td>
      <td width="150"><% =rs(11) %></td>
      <td width="80"><% =rs(11) %></td>
      <td width="150"><% =rs(14) %></td>  
    </tr>  
    <% rs.movenext%>  
    <%next%>  
  </table>  
</div>  
<%'end if%>  
<%Set Conn=nothing%>         
  
<%scriptname=request.servervariables("script_name")%>  
<br>  
<a href="<%=scriptname%>?whichpage=1&pagesize=<%=mypagesize%>&t1=<%=t1%>&t2=<%=t2%>&t3=<%=t3%>">第一页</a>&nbsp;  
<a href="<%=scriptname%>?whichpage=<%=nextpage%>&pagesize=<%=mypagesize%>&t1=<%=t1%>&t2=<%=t2%>&t3=<%=t3%>">下一页</a>&nbsp;  
<a href="<%=scriptname%>?whichpage=<%=prepage%>&pagesize=<%=mypagesize%>&t1=<%=t1%>&t2=<%=t2%>&t3=<%=t3%>">上一页</a>&nbsp;&nbsp;  
<a href="<%=scriptname%>?whichpage=<%=maxcount%>&pagesize=<%=mypagesize%>&t1=<%=t1%>&t2=<%=t2%>&t3=<%=t3%>">最后一页</a>&nbsp;&nbsp;<p>  
<input type="submit" value="删除考生" name="cmddelks">&nbsp;&nbsp; &nbsp;&nbsp;<input type="submit" value="添加考生" name="cmdaddks">&nbsp;&nbsp;&nbsp;&nbsp; 
<input type="submit" value="修改考生" name="cmdmdyks">&nbsp;&nbsp; <a href="javascript:history.back(2)">返回</a>

</p>
</form>
 
<!--msnavigation--></td></tr><!--msnavigation--></table></body>
</html>       

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?