在登录按钮中写这个事件
protected void loginbtn_Click(object sender, EventArgs e)
{
string UserName = txtUserName.Text.Trim();
string Password = txtUserPwd.Text.Trim();
SqlConnection conn = new SqlConnection();
conn.ConnectionString =@"server=服务器名;uid=实例名;pwd=密码;database=数据库名";
string sqlString = "select UserID,UserName,UserPwd from [MyUser] where UserName='" + UserName + "'";
SqlDataAdapter sda = new SqlDataAdapter(sqlString, conn);
DataSet ds = new DataSet();
sda.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
Response.Write("");
//Response.End();
}
else
{
string Password_db = ds.Tables[0].Rows[0]["UserPwd"].ToString();
string UserID_db = ds.Tables[0].Rows[0]["UserID"].ToString();
if (Password == Password_db)
{
Response.Cookies["UserName"].Value = UserName;
Response.Cookies["UserID"].Value = UserID_db;
Response.Redirect("shouye.aspx");
}
else
{
Response.Write("");
txtUserPwd.Text = "";
}
你可以写SQL语句根据用户名检索密码,如果有能检索到存在项,再跟密码做匹配,成功则登陆呗,不成功调用js语句弹出对话框提示呗