做這個LoginDemo的目的是練習訪問數據庫,使用存儲過程,最後是寫成用戶類。
頁面組成:Default.aspx,LogSuccess.htm,LogFailure.htm
數據庫test,表User:UserID(自增),UserName,PassWord
前台:簡單的登陸界面
後台代碼:
1、很久以前做第一個例子的時候用的:
代碼
protected void CheckAccount()
{
string strConn = "server=localhost;uid=sa;pwd=123;database=test;";
SqlConnection conn = new SqlConnection(strConn);
String strComm = "Select * from Users where UserName ='" + UserName.Text + "' and PassWord= '" + PassWord.Text + "'";
SqlCommand comm = new SqlCommand(strComm, conn);
conn.Open();
SqlDataReader dr = comm.ExecuteReader();
if (dr.Read())
{
Response.Redirect("LogSuccess.htm");
}
else
{
Response.Redirect("LogFailure.htm");
}
conn.Close();
}