给你一个参考<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
...
@Page Language="C#" Debug="true"
%>
<% ... @import namespace="System.Data" %>
<% ... @import namespace="System.Data.OleDb" %>
< html >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=gb2312" >
< title > 登陆系统 </ title >
</ head >
< script language ="C#" runat ="server" > ...
OleDbConnection conn;
OleDbCommand cmd;
void Page_Load(Object sender,EventArgs e)
...{
string connstr="Provider=MicroSoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("zhuce.mdb");
conn=new OleDbConnection(connstr);
conn.Open();
}
void button1_click(Object sender,EventArgs e)
...{
if(Page.IsValid)
...{
string sqlstr="select * from zhuce where username='"+yhm.Text+"' and password='"+mm.Text+"'";
cmd=new OleDbCommand(sqlstr,conn);
OleDbDataReader reader;
reader=cmd.ExecuteReader();
if(reader.Read())
...{
Session["xm"]=reader["truename"];
Response.Redirect("aa.htm");
reader.Close();
}
else
...{
reader.Close();
label1.Text="用户名或密码错误";
yhm.Text="";
mm.Text="";
}
}
}
void button2_click(Object sender,EventArgs e)
...{
}
</ script >
< style > ...
.table{...}{position:absolute;width:300;filter:progid:DXImageTransform.Microsoft.gradient(enabled='true',GradientType=1,startColorstr=#808000, endColorstr=#FFFF00) ;}
tr{...}{font:9pt verdana;}
table{...}{border-top:#66ccff 1px solid;border-left:#66ccff 1px solid;border-right:#66ccff 1px solid;
border-bottom:#66ccff 1px solid;}
.textbox{...}{BACKGROUND: #ffffff; border:1 solid #6611ff; COLOR: #000000; FONT-SIZE: 9pt; FONT-STYLE: normal; FONT-VARIANT: normal; FONT-WEIGHT: normal; HEIGHT: normal; LINE-HEIGHT: normal}
.button{...}{background:#eeeeee;border:1 solid #6611ff;}
</ style >
< body >
< form runat ="server" >
< br >< br >< br >< br >
< table align ="center" width ="40%" cellpadding ="0" cellspacing ="0" border =1 >
< tr >
< td height ="20" bgcolor ="#66CCFF" > </ td >
</ tr >
< tr >
< td height ="149" align ="center" > < asp:label ID ="label1" runat ="server" />
< table >
< tr >
< td > 用户名: < asp:textbox ID ="yhm" runat ="server" size ="15" class ="textbox" />
< asp:requiredfieldvalidator ID ="rfvyhm" ControlToValidate ="yhm" runat ="server"
InitialValue ="" Display ="Dynamic" ErrorMessage ="用户名不能为空" />
</ td >
</ tr >
< tr >
< td >
密 码: < asp:textbox ID ="mm" runat ="server" TextMode ="Password" size ="15" class ="textbox" />
< asp:requiredfieldvalidator ID ="rfvmm" ControlToValidate ="mm" runat ="server"
InitialValue ="" Display ="Dynamic" ErrorMessage ="请输入密码" />
</ td >
</ tr >
< tr >
< td align ="center" >< asp:button ID ="button1" OnClick ="button1_click" runat ="server" Text ="确定" class ="button" />
< asp:button ID ="button2" OnClick ="button2_click" runat ="server" Text ="取消" class ="button" />
</ td >
</ tr >
</ table >
</ td >
</ tr >
< tr >
< td height ="20" bgcolor ="#66FFFF" ></ td >
</ tr >
</ table >
</ form >
</ body >
</ html >
<% ... @import namespace="System.Data" %>
<% ... @import namespace="System.Data.OleDb" %>
< html >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=gb2312" >
< title > 登陆系统 </ title >
</ head >
< script language ="C#" runat ="server" > ...
OleDbConnection conn;
OleDbCommand cmd;
void Page_Load(Object sender,EventArgs e)
...{
string connstr="Provider=MicroSoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("zhuce.mdb");
conn=new OleDbConnection(connstr);
conn.Open();
}
void button1_click(Object sender,EventArgs e)
...{
if(Page.IsValid)
...{
string sqlstr="select * from zhuce where username='"+yhm.Text+"' and password='"+mm.Text+"'";
cmd=new OleDbCommand(sqlstr,conn);
OleDbDataReader reader;
reader=cmd.ExecuteReader();
if(reader.Read())
...{
Session["xm"]=reader["truename"];
Response.Redirect("aa.htm");
reader.Close();
}
else
...{
reader.Close();
label1.Text="用户名或密码错误";
yhm.Text="";
mm.Text="";
}
}
}
void button2_click(Object sender,EventArgs e)
...{
}
</ script >
< style > ...
.table{...}{position:absolute;width:300;filter:progid:DXImageTransform.Microsoft.gradient(enabled='true',GradientType=1,startColorstr=#808000, endColorstr=#FFFF00) ;}
tr{...}{font:9pt verdana;}
table{...}{border-top:#66ccff 1px solid;border-left:#66ccff 1px solid;border-right:#66ccff 1px solid;
border-bottom:#66ccff 1px solid;}
.textbox{...}{BACKGROUND: #ffffff; border:1 solid #6611ff; COLOR: #000000; FONT-SIZE: 9pt; FONT-STYLE: normal; FONT-VARIANT: normal; FONT-WEIGHT: normal; HEIGHT: normal; LINE-HEIGHT: normal}
.button{...}{background:#eeeeee;border:1 solid #6611ff;}
</ style >
< body >
< form runat ="server" >
< br >< br >< br >< br >
< table align ="center" width ="40%" cellpadding ="0" cellspacing ="0" border =1 >
< tr >
< td height ="20" bgcolor ="#66CCFF" > </ td >
</ tr >
< tr >
< td height ="149" align ="center" > < asp:label ID ="label1" runat ="server" />
< table >
< tr >
< td > 用户名: < asp:textbox ID ="yhm" runat ="server" size ="15" class ="textbox" />
< asp:requiredfieldvalidator ID ="rfvyhm" ControlToValidate ="yhm" runat ="server"
InitialValue ="" Display ="Dynamic" ErrorMessage ="用户名不能为空" />
</ td >
</ tr >
< tr >
< td >
密 码: < asp:textbox ID ="mm" runat ="server" TextMode ="Password" size ="15" class ="textbox" />
< asp:requiredfieldvalidator ID ="rfvmm" ControlToValidate ="mm" runat ="server"
InitialValue ="" Display ="Dynamic" ErrorMessage ="请输入密码" />
</ td >
</ tr >
< tr >
< td align ="center" >< asp:button ID ="button1" OnClick ="button1_click" runat ="server" Text ="确定" class ="button" />
< asp:button ID ="button2" OnClick ="button2_click" runat ="server" Text ="取消" class ="button" />
</ td >
</ tr >
</ table >
</ td >
</ tr >
< tr >
< td height ="20" bgcolor ="#66FFFF" ></ td >
</ tr >
</ table >
</ form >
</ body >
</ html >