62,025
社区成员
发帖
与我相关
我的任务
分享
protected void ButtonLogin_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DBConnectionString"]); //创建连接对象
SqlCommand cmd = new SqlCommand("select * from Users where userId='" + txtUserName.Text + "'", conn); //创建查询用户名是否存在数据对象
try
{
conn.Open(); //打开连接
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read()) //如果用户名输入正确
{
if (sdr["userPwd"].ToString() == txtPassword.Text)//密码正确
{
conn.Close();
Session["userID"] = txtUserName.Text.Trim();//存储用户名
Response.Redirect("AddressList.aspx"); //进入系统
}
else
{
Response.Write("<script language=javascript>alert('您输入的密码错误!')</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('您输入的用户名错误或该用户名不存在!')</script>");
}
}
catch (System.Exception ee)
{
Response.Write("<script language=javascript>alert('" + ee.Message.ToString() + "')</script>");
}
finally
{
conn.Close();
}
}