是用來新手入門的,高手們不要見笑呀!
string conn = "server=.;database=login;user id=sa;pwd=123";
SqlConnection cn = new SqlConnection(conn);
cn.Open();
string strsql = "select user_name,user_pwd from admin where user_name='" + TextBox1.Text + "' or user_pwd='" + TextBox2.Text + "'";
SqlCommand cmd = new SqlCommand(strsql, cn);
SqlDataReader rd = cmd.ExecuteReader();
if (rd.Read())
{
if (rd.GetValue(0).ToString() == TextBox1.Text)
{
if (rd.GetValue(1).ToString() == TextBox2.Text)
{
Response.Redirect("Default.aspx");
}
else
{
Response.Write("<script>alert('密碼錯誤!')</script>");
}
}
else
{
Response.Write("<script>alert('用戶名錯誤!')</script>");
}
}
else
{
Response.Write("<script>alert('用戶不存在!')</script>");
}
}