protected void Button1_Click(object sender, EventArgs e)
{
string Username = this.TextBox1.Text;
string Password=this.Label1.Text;
string num = ("Server=(local);Integrated Security=SSPI;database=stu");
//找到数据库stu并且找到其中的表格connection,用一条记录作为连接桥梁:
SqlConnection connect = new SqlConnection(num); //建立一个数据库连接对象connect
string sql = "select * from connection where Username='"+ Username + "' and Password='"+Password + "'";
//SQL server数据库打开并连接:
SqlCommand command = new SqlCommand(sql,connect); //建立一个新的SQL命令
connect.Open();
//SQL server数据库连接关闭:
connect.Close();
//将你从界面输入框中取得的两个数据与数据库中数据进行验证过程:
int count = Convert.ToInt32(command.ExecuteScalar());
if (count > 0)
{
Response.Redirect("登入成功!");
}
else
{
Response.Write("<script> alert('用户名或密码不正确!')</script>");
}
}
}
}
