为什么我的自定义登陆控件不能用?
毕业了,想做个网站用来放一些同学的资料,做了个登陆控件,却不能达到预期效果,自己也找不出什么毛病,还望有人告诉我啊。
Web控件:
protected System.Web.UI.WebControls.RadioButtonList rbtLoginChk;
protected System.Web.UI.WebControls.TextBox txtLoginPwd;
protected System.Web.UI.WebControls.LinkButton lbtnLostPwd;
protected System.Web.UI.WebControls.TextBox txtLoginUser;
protected System.Web.UI.WebControls.Button btnLoginIn;
编写的代码:
private void btnLoginIn_Click(object sender, System.EventArgs e)
{
string LoginUser = this.txtLoginUser.Text.ToString(); //获取登陆用户
string LoginPwd = this.txtLoginPwd.Text.ToString(); //获取登陆密码
int Result; //定义Result字符串用于把cmd.ExecuteScalar转化为Int类型
SqlConnection con = new SqlConnection("server=.;database=txl;uid=sa;pwd=sa;");
con.Open();
if(this.rbtLoginChk.SelectedItem.Text == "姓名") //以姓名方式登陆
{
SqlCommand cmd = new SqlCommand("select personName,personPwd from beadroll where personName = '"+LoginUser+"' and personPwd = '"+LoginPwd +"'",con); //根据输入的数据从数据库中检索姓名、密码登陆
Result = Convert.ToInt32(cmd.ExecuteScalar());
}
else //以学号方式登陆
{
SqlCommand cmd = new SqlCommand("select personID,personPwd from beadroll where personID = '"+LoginUser+"' and personPwd = '"+LoginPwd+"'",con); //根据输入数据从数据库中检索学号、密码登陆
Result = Convert.ToInt32(cmd.ExecuteScalar());
}
if(Result>0) //有返回值
{
Response.Redirect("correct.aspx");
}
else //返回值为空
{
Response.Redirect("false.aspx");
}
}