在命名空间BussinessLogicLayer里的User方法代码如下: 
using MyChatRoom.DataAccessLayer; 
namespace MyChatRoom.BussinessLoginLayer 

    
    public class User 
    { 
        private string _userName; 
        private string _passWord; 
        private bool _Exist; 
        /// <summary> 
        /// 根据参数userName,获取用户详细信息 
        /// </summary> 
        public void LoadData(string userName) 
        { 
            Database db = new Database(); //实例化一个Database类 
            string Sql="select * from [User] where UserName='"+userName+"'"; 
            DataRow dr = db.GetDataRow(Sql); //利用Database类里的GetDataRow方法查询数据库 
            if (dr != null) 
            { 
                this._userName = dr["UserName"].ToString(); 
                this._passWord = dr["PassWord"].ToString(); 
                this._Exist = true; 
            } 
            else 
                this._Exist = false; 
        } 
    public void Add(string userName, string passWord) 
        { 
            Database db = new Database(); //实例化一个Database类 
            string Sql = "insert [User] values('"+userName+"','"+passWord+"')"; 
            db.ExecuteSQL(Sql); //利用Database类里的ExecuteSQL方法插入数据 
        } 

用户界面里Button_onclick的代码如下: 
  protected void Button1_Click(object sender, EventArgs e) 
    { 
        string userName = txtUserName.Text.Trim(); 
        string passWord = txtPassWord.Text.Trim(); 
        MyChatRoom.BussinessLoginLayer.User user = new User(); 
        user.LoadData(userName);  //获取用户信息 
        if (user.Exist) 
        { 
            Response.Redirect("Main.aspx"); 
        }  
    } 这里有个错误  user.Exist //在实例化的user里找不到的 
大侠教教我 要在User方法里怎么修改阿?

解决方案 »

  1.   


     if (user.Exist) 
            { 
                Response.Redirect("Main.aspx"); 
            }  
    改为
     if (user._Exist) 
            { 
                Response.Redirect("Main.aspx"); 
            }  
      

  2.   


    改为
     if (this._Exist) 
            { 
                Response.Redirect("Main.aspx"); 
            }  
      

  3.   

    public bool _Exist; 
    User user = new User();
      

  4.   

    有2种方法:
    1、把_Exist设置为属性;
    private bool _Exist; 
    public bool Exist{
        get{return _Exist;}
    }
    这样就可以user.Exist 了2、在LoadData方法里返回
    如:
    public bool LoadData(string userName) 

        Database db = new Database(); //实例化一个Database类 
        string Sql="select * from [User] where UserName='"+userName+"'"; 
        DataRow dr = db.GetDataRow(Sql); //利用Database类里的GetDataRow方法查询数据库 
        if (dr != null) 
        { 
            this._userName = dr["UserName"].ToString(); 
            this._passWord = dr["PassWord"].ToString(); 
            return true; 
        } 
        else 
            return false; 
    } 你的代码改成:
    if (user.LoadData(userName))   //获取用户信息 

        Response.Redirect("Main.aspx"); 
    }  
      

  5.   

    加一个属性就可以了在命名空间BussinessLogicLayer里的User方法代码如下: 
    using MyChatRoom.DataAccessLayer; 
    namespace MyChatRoom.BussinessLoginLayer 

        
        public class User 
        { 
            private string _userName; 
            private string _passWord; 
            private bool _Exist; 
            /// <summary> 
            /// 根据参数userName,获取用户详细信息 
            /// </summary> 
            public void LoadData(string userName) 
            { 
                Database db = new Database(); //实例化一个Database类 
                string Sql="select * from [User] where UserName='"+userName+"'"; 
                DataRow dr = db.GetDataRow(Sql); //利用Database类里的GetDataRow方法查询数据库 
                if (dr != null) 
                { 
                    this._userName = dr["UserName"].ToString(); 
                    this._passWord = dr["PassWord"].ToString(); 
                    this._Exist = true; 
                } 
                else 
                    this._Exist = false; 
            }
            public bool   Exist
            {
              get{return _Exist;}
              set{_Exist= value;}
            } 

              public void Add(string userName, string passWord) 
            { 
                Database db = new Database(); //实例化一个Database类 
                string Sql = "insert [User] values('"+userName+"','"+passWord+"')"; 
                db.ExecuteSQL(Sql); //利用Database类里的ExecuteSQL方法插入数据 
            } 

    用户界面里Button_onclick的代码如下: 
      protected void Button1_Click(object sender, EventArgs e) 
        { 
            string userName = txtUserName.Text.Trim(); 
            string passWord = txtPassWord.Text.Trim(); 
            MyChatRoom.BussinessLoginLayer.User user = new User(); 
            user.LoadData(userName);  //获取用户信息 
            if (user.Exist) 
            { 
                Response.Redirect("Main.aspx"); 
            }  
        } 
      

  6.   

    加一段
    public bool Exist{
       get(return this._Exist;}
    }你以前做啥编程的啊,VB还是C啊?_这样的前缀命名规则真别扭啊
      

  7.   

    private string _userName; 
            private string _passWord; 
            private bool _Exist; 这些是私有成员变量  你重构给类对应,加上属性就可以用 user.Exist  
      

  8.   

    这里有个错误  user.Exist //在实例化的user里找不到的 
    你的程序中并没有加Exist属性。只是设置了一个_Exist变量
    在User类中加一个
    Public bool Exist
    {
       get
       {
         return _Exist;
        }
    }
    即可
      

  9.   


    public bool Exist
    {
    get
    {
    return this._exist;
    }
    }加上就能找到了。
      

  10.   

    还有其他的public string UserName
    {
    set
    {
    this._userName=value;
    }
    get
    {
    return this._userName;
    }
    }
    public string Password
    {
    set
    {
    this._password=value;
    }
    get
    {
    return this._password;
    }
    }
      

  11.   

    public bool Exist
    {
          get
          {
              return this._exist;
          }
    }
      

  12.   


      protected void Button1_Click(object sender, EventArgs e) 
        { 
            string userName = txtUserName.Text.Trim(); 
            string passWord = txtPassWord.Text.Trim(); 
            MyChatRoom.BussinessLoginLayer.User user = new User(); 
            user.LoadData(userName);  //获取用户信息 
            if(user.Exist) //如果是老用户
    {
    if(user.Password==password) {
    Response.Redirect("Main.aspx");
    }
    else {
    Response.Write("<Script Language=JavaScript>alert(\"验证失败,请重新登录!\")</Script>");
    }
    }  
        } 
    最好再验证一下密码是否正确
      

  13.   

    User类中少一属性:Existpublic string Exist
    {
    get{ return _Exist; }
    }
      

  14.   

          public bool  Exist 
            { 
              get{return _Exist;} 
              set{_Exist= value;} 
            } 
      

  15.   

    1楼的很正确阿
    但是前提是要把 private改成public 在button_click里才可以引用