Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Foreach loop through sqldatasource result set

Status
Not open for further replies.

xavstone

Technical User
Apr 12, 2005
33
GB
Hi All,

I am trying to find a way to loop through the results of a stored procedure using foreach. Its part of an approach to populate a treeview.

I was hoping that some of you could provide an example snippet on how they might go about it.

Thanks as always in advance...

Ben
 
When you get your results from the stored procedure it should be returned as a dataset correct?

in which case you can find the table that contains your data and iterate through each row.

DataSet ds = new DataSet();

//runyoursql using your dataset (ds)

foreach (DataRow row in ds.Tables[0].Rows)
{
Console.WriteLine(row[0].ToString());
Console.WriteLine(row["FieldName"].ToString());
}

Now you have access to each row returned in the result set.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top