第1个回答 2012-01-03
protected void Button1_Click(object sender, EventArgs e)
{ if (TextBox1.Text.Trim() == "" || TextBox2.Text.Trim() == "")
{
Response.Write("<script language=javascript>alert('用户名或密码不能为空');</script>");
return;
}
SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ToString());
Conn.Open();
string StringSQL = "select * from ReaderInfo where userName='" + TextBox1.Text + "'and Password='" + TextBox2.Text + "'";
SqlCommand SelectCom = new SqlCommand(StringSQL, Conn);
SqlDataReader dr = SelectCom.ExecuteReader();
if (!dr.Read())
{
Response.Write("<script language=javascript>alert('读者姓名或密码错!');</script>");
}
else
{
Session["userName"] = dr["ReaderName"];
Response.Redirect("default.aspx");
}
dr.Close();
Conn.Close();
}