首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

验证用户登录!解决办法

2012-03-01 
验证用户登录!protected void Button1_Click(object sender, EventArgs e){SqlConnection con DB.create

验证用户登录!
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 返回的是首行首列

热点排行