读书人

验证用户登录!解决办法

发布时间: 2012-03-01 10:25:46 作者: rapoo

验证用户登录!
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = DB.createcon();
con.Open();
SqlCommand sc = new SqlCommand("select * from userlogin where username='"+this.TextBox1.Text+"'AND userpass='"+this.TextBox2.Text+"'",con);

int count = Convert.ToInt32(sc.ExecuteScalar());
if (count != 1)
{
Response.Write("<script>alert('用户名密码错误')</script>");
}
else
{
Response.Redirect("success.aspx");
}







int count = Convert.ToInt32(sc.ExecuteScalar());
这句报出异常不知道怎么回事,希望各位帮我解决下,小弟在此谢谢了!!!!

[解决办法]
SqlCommand sc = new SqlCommand("select count(id) from userlogin where username='"+this.TextBox1.Text+"'AND userpass='"+this.TextBox2.Text+"'",con);
[解决办法]
用COunt就可以!
[解决办法]
抱歉写错了

ExecuteScalar 返回的是首行首列

读书人网 >asp.net

热点推荐