public partial class _Default : System.Web.UI.Page 
{    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txtid.Text =="")
        {
            Response.Write("<script language='javascript'>alert('请输入用户名!!');</script>");
            txtid.Focus();
            return;
        }
        if (txtpwd.Text == "")
        {
            Response.Write("<script language='javascript'>alert('请输入密码!!');</script>");
            txtpwd.Focus();
            return;
        }
        try
        {
   
           string sqlstr="select count(*) from Login where Userid = '"+txtid.Text+"'and Password = '"+txtpwd.Text+"'";
           int count = DBHelper.GetScalar(sqlstr);
          
           if(count==1)
           {
               Response.Redirect("Default2.aspx");             }
            else
            {
                Response.Write("<script>('登录失败!!!')</script>");            }
        }
        catch (SqlException ex)
        {
            Response.Write("<script>('登录失败!!!')</script>");        }
        finally
        {
            DBHelper.Connection.Close();
        }    }
是不是int count = DBHelper.GetScalar(sqlstr);
这段的问题啊???求高手指点

解决方案 »

  1.   

    int count = (int)DBHelper.GetScalar(sqlstr);
      

  2.   

    int count = (Convert.ToInt32)DBHelper.GetScalar(sqlstr);
     
      

  3.   

    还是不行啊。。断点的那个count的值变成了-1;
     
      

  4.   

    出丑大了 int count = Convert.ToInt32(DBHelper.GetScalar(sqlstr));
      

  5.   

    你应该断点看sqlstr,然后在数据库中执行看看返回结果
      

  6.   

    报的什么错误都不知道,怎么看呢,还有你的GetScalar这个方法返回的是int类型还是??
      

  7.   

    你的sql语句就有问题..都返回-1了..表示没数据.. .未将对象引用至对象的错误
      

  8.   

    string sqlstr="select count(*) from Login where Userid = '"+txtid.Text+"'and Password = '"+txtpwd.Text+"'";
    Password = '"+txtpwd.Text+"'";  这里很明显引号打错了