日期:2014-05-17  浏览次数:20435 次

asp.net网站做了个登录,出现错误,求大神帮助
本帖最后由 wang0921zheng 于 2013-02-07 00:46:35 编辑
我做了个登录页面,如果输入正确的账号和密码,就可以运行。但是如果故意输错账号或密码,就会出现错误
下面是代码,UserLogin是个存储过程,错误就是 if(dsTable.Rows.Count>0)这行,说未将对象引用设置到对象实例中。。。。
 protected void btnLogin_Click(object sender, EventArgs e)
    {
            CommonClass cc = new CommonClass();
            DB db = new DB();
            UserClass uc = new UserClass();
            string num = this.txtValidateNum.Text.Trim();
            Session["UserID"] = null;
            Session["UserName"] = null;
            if (this.txtUserName.Text.Trim() == "" || this.txtPwd.Text.Trim() == "")
            {
                Response.Write(cc.MessageBox("登录名和密码不能为空!", "Default.aspx")); ;
            }
            else
            {
                if (Session["ValidateNum"].ToString() == num.ToUpper())——这行是验证码的验证
                {
                    DataTable dsTable = uc.UserLogin(this.txtUserName.Text.Trim(), this.txtPwd.Text.Trim());
                    if (dsTable.Rows.Count>0)
                    {
                        Session["UserID"] = Convert.ToInt32(dsTable.Rows[0][0].ToString());
                        Session["UserName"] = dsTable.Rows[0][1].ToString();
                        Response.Redirect(Request.CurrentExecutionFilePath);
                    }
                    else
                    {

                        Response.Write(cc.MessageBox("用户名或密码错误,请重新输入!", "Default.aspx"));
     &