Hi,
Can anyone tell me how to retrieve record values from a datatable?.My requirement is like:
Within a for loop I am executing different stored procedures and storing records in a datatable so that i cannot specify paticular column names.i want to write the first row values of each result into a log file.(application is windows service)
Code is :
DataTable dtTransID = new DataTable();
DBConnect();
string sp=" exec "+storedProcedure+" ";
dtTransID =mDB.RunSp(sp);
if(dtTransID.Rows.Count >0)
{
for(i=0;i
if (storedProcedure!=null)
{
message = message + Datetime.Now+ "\n + dtTransID.Rows[0] +, - ";
message = message + dtTransID.Rows[0] + ",";
Globals.log.logMessage(message);
}
dtTransID.Rows[0] -This line is returning 'system.data.rows' not any records.
Please help me..
Thanks in advance
Thirupathi vPosted Oct 20, 2008, 5:25 AM
Hi First you should fill the Values from database to datatable. like.
dim Ds as new Dataset
dim Cmd as new sqlcommand("Exec " ,con)
dim ada as new sqldataadapter(cmd)
ada.Fill(Dataset,"DataTableName")
Now you have to decalre the Datatable Like
Dim Dt as data.DataTable=Ds.DatatableName
Dim Dr() as data.DataRow=Dt.Select();
For i = 0 to Dr.Length-1
lbl.Text=Dr(i).Item("FieldName")
Next
By using the above code, we can retrive the all values from DataTable.