1.11M Members

How to loop through dataset

 
0
 

Hi All,

I am trying to loop through the values of a dataset. Using a 3-tier architecture...so the dataset is created in the BLL. Now i want to retrieve its values and proceed with my desired functionality for each value of the dataset. Can somebody help as I am new to this and don't have much idea about it.

Thanks in advance.

 
0
 

Try this section of code,basically what it does is this. it gets the DataTable rows inside the dataset(getDataSet) so that you can be able to accsess your desired values.

DataTable myTable = GetDataSet.Tables[0];
	foreach (DataTable DT in GetDataSet.Tables)
	{
		foreach (DataRow in DR myTable.Rows)
		{
			string value1;
			string value2;
			if(condition1==true)
			{
				value1 = DR[1];
				value2 = DR[2];
			}
		}
	}
 
0
 

do you really need that first foreach loop? If you're already getting myTable, just do a foreach on the DataRows in myTable.Rows directly...

 
0
 

You dont actually need it, if you know the actual table name you can actually skip the first foreach loop and go directly to the "DataRows myTable.Rows",its a peference that has helped me adapt to my work situation.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article