

public WebForm1()
{
Page.Init += new System.EventHandler(Page_Init);
}
private void Page_Load(object sender, System.EventArgs e)
{
}
private void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
string strConnection="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath(".")+"..\\user.mdb;";
//user.mdb放在与aspx文件同一目录下
myConn=new OleDbConnection(strConnection);
}
private void InitializeComponent()
{
this.LogButton.Click += new System.EventHandler(this.LogButton_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
private void LogButton_Click(object sender, System.EventArgs e)
{
string userid,pwd;
userid=Userid.Text;
pwd=Pwd.Text;
string mySel="SELECT count(*) as iCount from user where UserID=""+userid+""";
OleDbCommand myCmd1=new OleDbCommand(mySel,myConn);
myCmd1.Connection.Open();
OleDbDataReader Dr1;
Dr1=myCmd1.ExecuteReader();
Dr1.Read();
string Count=Dr1["iCount"].ToString();
Dr1.Close();
myCmd1.Connection.Close();
string DrPwd,DrRoles;
if(Count!="0")
{
mySel="SELECT * from user where UserID=""+userid+""";
OleDbCommand myCmd=new OleDbCommand(mySel,myConn);
myCmd.Connection.Open();
OleDbDataReader Dr;
Dr=myCmd.ExecuteReader();
Dr.Read();
DrPwd=Dr["Password"].ToString();
Dr.Close();
if(DrPwd==pwd)
{
Session["logid"]=userid;//新建一个Session
Response.Redirect("main.aspx");
}
else
Msg.Text="登录密码错.";
}
else