日期:2014-05-17 浏览次数:20649 次
public bool checklogin(string name,string pwd)
{
SqlConnection conn = new SqlConnection(sqlstr);
conn.Open();
// 创建命令(SqlCommand)对象(cmd)
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn; // 指示命令发给哪个数据库
cmd.CommandType = CommandType.Text; // 指示是什么类型的命令
cmd.CommandText = "SELECT [username],[password] FROM [user] WHERE [username]=@name and [password]=@pwd";
SqlDataReader read = cmd.ExecuteReader();
if (read.Read())
{
return true;
}
else {
return false;
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
string name = this.txtName.Text; //得到登陆帐号
string pwd = this.txtpwd.Text; //得到登陆密码
sql db = new sql();
bool cklogin=db.checklogin(name,pwd);
if(cklogin=true){
Response.Write("<script>alert('恭喜你登录成功')</script>");
}
else{
Response.Write("<script>alert('恭喜你登录失败')</script>");
}
}