I have a C# project that uses datasets to pull data out of a SQL server database. I have 3 controls on the windows form that are bound to the dataset, but I have a 4th attribute that I want sent to a variable in the business layer.
I could set the variable to the text property of a textbox and make the textbox invisible, but that seems like cheating. How do I take that attribute from the dataset and assign it to a string variable?
I would recommend creating an accessor (getting/setter) in your Business layer. Then when you retrieve your dataset values assign this variable to the value of the row/column in your dataset.
Business Layer
- namespace buslayer
-
private string _variable;
-
public string Variable()
-
{
-
set {_variable = value;}
-
}
C# project that pulls data from database
- private string attribute4 = "";
-
attribute4 = dataset.Tables[0].Rows[0]["ColumnName"].ToString();
-
if(attribute4 != null && attribute4 != "")
-
{
-
buslayer.Variable = attribute4.ToString();
-
}
By making the variable public in your business layer you should have the ability to assign its value from the dataset.
Nathan