DropDownList1中如何取值跟数据库中的作对比
intType=int.Parse(this.DropDownList1.SelectedValue.ToString());SqlCommandscd=newSqlCo...
int Type = int.Parse(this.DropDownList1.SelectedValue.ToString());
SqlCommand scd = new SqlCommand("select count(*) as ff from tb_user where username='" + username + "' userpwd='" + userpwd + "' and role='" + Type + "'", strcon);
int count = Convert.ToInt32(scd.ExecuteScalar());
if (count > 0)
{
HttpCookie mycookie = new HttpCookie("login");
mycookie.Values.Add("_name", username);
mycookie.Values.Add("_role", DropDownList1.SelectedValue);
TimeSpan ts = new TimeSpan(3, 0, 30, 0);
DateTime dt = DateTime.Now;
mycookie.Expires = dt.Add(ts);
Response.AppendCookie(mycookie);
Session["username"] = username;
Response.Redirect("index.aspx");
}
else
{
Response.Write("<script>alert('用户名或者密码错误,请重新输入!');history.back()</script>");
return;
}
我想获取DropDownList1中的值与数据库中的role比较,对了就登录成功,错了就报错。 展开
SqlCommand scd = new SqlCommand("select count(*) as ff from tb_user where username='" + username + "' userpwd='" + userpwd + "' and role='" + Type + "'", strcon);
int count = Convert.ToInt32(scd.ExecuteScalar());
if (count > 0)
{
HttpCookie mycookie = new HttpCookie("login");
mycookie.Values.Add("_name", username);
mycookie.Values.Add("_role", DropDownList1.SelectedValue);
TimeSpan ts = new TimeSpan(3, 0, 30, 0);
DateTime dt = DateTime.Now;
mycookie.Expires = dt.Add(ts);
Response.AppendCookie(mycookie);
Session["username"] = username;
Response.Redirect("index.aspx");
}
else
{
Response.Write("<script>alert('用户名或者密码错误,请重新输入!');history.back()</script>");
return;
}
我想获取DropDownList1中的值与数据库中的role比较,对了就登录成功,错了就报错。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询