1,105,594 Community Members

How to loop through dataset

Member Avatar
Shama1234
Newbie Poster
1 post since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
samacoba
Light Poster
25 posts since Jun 2010
Reputation Points: 10 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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];
			}
		}
	}
Member Avatar
alc6379
Cookie... That's it
2,752 posts since Dec 2003
Reputation Points: 105 [?]
Q&As Helped to Solve: 154 [?]
Skill Endorsements: 4 [?]
Team Colleague
 
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...

Member Avatar
samacoba
Light Poster
25 posts since Jun 2010
Reputation Points: 10 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article