asp.net网络考试系统分析

/Files/izxp/kaoshi.rar
<% @ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<Script runat="server">
void Page_Load(Object Src, EventArgs E) {
 string No = "";
 string Name = "";
 string Lesson = "";
 string Msg = "";
 if (IsPostBack) {//页面被提交的时候执行
  No = Request["txtNo"];
  Name = Request["txtName"];
  Lesson = Request["Lesson"];
  string SQL = "Select * From 成绩单 ";
  SQL = SQL + "Where 学号=" + "'" + No + "'" + " And 姓名='" + Name + "'";
//string SQL = "Select * From 成绩单 where 学号='"+No+"' and 姓名='"+Name+"'  ";
  OleDbConnection Conn;
  Conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"+
   "Data Source="+Server.MapPath("test.mdb"));
  Conn.Open();
        //Response.Write(SQL);
  OleDbCommand Comm=new OleDbCommand(SQL,Conn);
  OleDbDataReader dr=Comm.ExecuteReader();
  if (dr.Read())  {
   if (dr[Lesson].ToString() != "-1") {
    Msg = "你已经考过本科目了!";
   }
   else{
   Conn.Close();
   Response.Redirect("TEST.ASPX?Lesson="+Lesson+"&Name="+Name+"&No="+No);
//Response.Redirect("TEST.ASPX?Lesson="+Lesson+"&Name="+Name+"&No="+No+"");
   }
  }
  else{
   Msg = "你不是合法考生!";

  }
  Message.Text = Msg;
  Conn.Close();
 }

}
</Script>
<HTML>
 <BODY BGCOLOR=BEIGE>
 <H1 ALIGN="CENTER">在线考试系统</H1>
 <HR>
<FORM METHOD="POST" RUNAT="SERVER">
 <asp:DropDownList ID="Lesson" RUNAT="server">
      <asp:ListItem value="ASP" selected="true">ASP</asp:ListItem>
      <asp:ListItem value="XML">XML</asp:ListItem>
   </asp:DropDownList>
 <P>姓名:<asp:textbox id="txtName" runat="server" /></P>
 <P>学号:<asp:textbox id="txtNo" runat="server" /></P>
 <P><asp:button text="开始考试" runat="server" /></P>
 </FORM> <HR>
  <asp:label id="Message" runat="server" />
 </BODY>
</HTML>

 


 

posted @ 2006-12-01 12:04  平平  阅读(760)  评论(0编辑  收藏  举报