user code module - currently I am retreiving data from sql server and passing as parameter to the method, but i can't figure out how to separate query and entering data to the object. Thank you in advance.
while(myReader.Read())
{
_scenarioID = myReader["scenarioid"].ToString(); column
_scenarioDescr = myReader["descr"].ToString();
enterID(_scenarioID);
enterScenaDes( _scenarioDescr );
}
--------how will i hold the data after query , then process outside the while loop,
data encapsulation
Re: data encapsulation
Load the reader into a datatable - that will allow you to close the connection to the DB and read data whenever/however you want.
To check this works, you can add the following extension method to your framework and then execute dt.OutputDatatable-
Code: Select all
DataTable dt = new DataTable();
myReader = command.ExecuteReader();
dt.Load(myReader);
Code: Select all
public static void OutputDatatable(this DataTable dt){
int index = 0;
foreach (DataRow row in dt.Rows) {
Console.Write("Row " + index.ToString() + "= ");
foreach (DataColumn col in dt.Columns) {
string val = row[col].ToString();
if(string.IsNullOrEmpty(val)){
val = "NULL";
}
Console.Write(val + " , ");
}
Console.Write("\n");
index++;
}
}
Re: data encapsulation
Thank you so much for your help, learning the datatable in progress.
thanks,
Omayer
thanks,
Omayer
Tipu