根据选择的值过滤记录 [英] Filtering record according to selected value
问题描述
嗨
我试图根据选定的值过滤记录,现在它给了我一个我从未见过的怪异错误,即"ClsLibUserman.dll中发生了类型为"System.StackOverflowException"的未处理异常",该错误指向下面的代码
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
public int RightID
{
get { return RightID; }
set { RightID = value; }
}
以下是我的课程
Below is my class
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
下面是我的代码形式mainwindow.xaml.cs
Below is my code form mainwindow.xaml.cs
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();
}
从我的存储过程中添加RightID后,发生了错误
The error occured after adding RightID from my stored procedure
推荐答案
代码的开头就说明了一切:
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.
这篇关于根据选择的值过滤记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!