Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate through DataSet

Tags:

c#

dataset

I have a DataSet named DataSet1. It contains an unknown number of tables and an unknown number of columns and rows in those tables. I would like to loop through each table and look at all of the data in each row for each column. I'm not sure how to code this. Any help would be appreciated!

like image 784
user902949 Avatar asked May 30 '12 18:05

user902949


2 Answers

foreach (DataTable table in dataSet.Tables) {     foreach (DataRow row in table.Rows)     {         foreach (object item in row.ItemArray)         {             // read item         }     } } 

Or, if you need the column info:

foreach (DataTable table in dataSet.Tables) {     foreach (DataRow row in table.Rows)     {         foreach (DataColumn column in table.Columns)         {             object item = row[column];             // read column and item         }     } } 
like image 122
Steven Doggart Avatar answered Sep 20 '22 03:09

Steven Doggart


Just loop...

foreach(var table in DataSet1.Tables) {     foreach(var col in table.Columns) {        ...     }     foreach(var row in table.Rows) {         object[] values = row.ItemArray;         ...     } } 
like image 39
Marc Gravell Avatar answered Sep 21 '22 03:09

Marc Gravell