Click here to Skip to main content
15,896,343 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
I tried to filter record according to the selected value, now its giving me a weird error that i hav never seen sayn "An unhandled exception of type 'System.StackOverflowException' occurred in ClsLibUserman.dll" this error points to this code below

C#
public int RightID
       {
           get { return RightID; }
           set { RightID = value; }
       }



Below is my class

C#
public ClsUsers(string firstName, string surname,int rID, string uID, string mail,  string rName, string description)
        {
            fName = firstName;
            sName = surname;
            email = mail;
            rightID = rID;
            userID = uID;
            rightName = rName;
            desc = description;
        }



        public string FName
        {
            get { return fName; }
            set { fName = value; }
        }

        public string SName
        {
            get { return sName; }
            set { sName = value; }
        }

        public int RightID
        {
            get { return RightID; }
            set { RightID = value; }
        }

        public string UserID
        {
            get { return userID; }
            set { userID = value; }
        }

        public string Email
        {
            get { return email; }
            set { email = value; }
        }

        public string RightName
        {
            get { return rightName; }
            set { rightName = value; }
        }
        public string Desc
        {
            get { return desc; }
            set { desc = value; }
        }



        public string Password
        {
            get { return password; }
            set { password = value; }
        }

        public string Username
        {
            get { return username; }
            set { username = value; }
        }



Below is the code from my business layer
#region GetSpecificUser()
       public ClsUsers GetSpecificUser(string UserID)
       {
           using (SqlConnection conn = new SqlConnection(ConnString))
           {
               SqlCommand cmd = new SqlCommand("procGetUserAndTheirRights", conn);
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.Add(new SqlParameter("@userID", SqlDbType.NVarChar));
               cmd.Parameters["@userID"].Value = UserID;
               ClsUsers users;
               try
               {
                   conn.Open();
                   SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
                   reader.Read();
                   users = new ClsUsers(Convert.ToString(reader["FName"]), Convert.ToString(reader["LName"]), Convert.ToInt32(reader["RightID"]), Convert.ToString(reader["UserID"]), Convert.ToString(reader["Email"]), Convert.ToString(reader["RightName"]), Convert.ToString(reader["Descriptions"]));
                   reader.Close();
               }
               catch (SqlException)
               {
                   throw new ApplicationException("Error reading Shipper info for shipper " + UserID + ".");
               }
               return users;
           }
       }
       #endregion


Below is my code form mainwindow.xaml.cs

C#
private void cboID_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             users = bl.GetSpecificUser((string)cboID.SelectedValue);
             txtname.Text = users.FName;
             txtSurname.Text = users.SName;
             txtViewEmail.Text = users.Email;
             txtViewRightsName.Text = users.RightName;
             txtViewDescription.Text = users.Desc;
             int var = users.RightID;
             txtRightID.Text = var.ToString();
         }




The error occured after adding RightID from my stored procedure
Posted
Updated 15-May-11 20:19pm
v2

1 solution

The very start of your code says it all:
public int RightID
       {
           get { return RightID; }
           set { RightID = value; }
       }
If you execute the code:
RightID = 6;
What happens?

You need to either use an automatic property:
public int RightID { get; set; }
Or declare and use a field as a property backing store:
private int rightID
public int RightID
       {
           get { return rightID; }
           set { rightID = value; }
       }
Either way should cure your problem.
 
Share this answer
 
Comments
Anele Ngqandu 16-May-11 2:45am    
I declared it rightID, but then it did the same thing...So i decided to delete the proparty and start a new one and its working now.
OriginalGriff 16-May-11 3:03am    
Good! I find the best way to do it is to declare the backing store first, then use "Refactor...Encapsulate Field" to ensure the property has a different name.
Anele Ngqandu 16-May-11 3:19am    
lovely!!I did the same 2...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900