Forum guidelines
AuthorQuestion
Loop through DataTable in C#
Posted on: 04 Feb 2012
Hi friends,

I want to know that how to loop through all rows of the DataTable?

AuthorReply
Re: Loop through DataTable in C#
Posted on: 04 Feb 2012  
If 'dt' is your datatable, you can loop through its rows using a foreach statement as follows:

foreach(DataRow dr in dt.Rows)
{
   // do something with dr
}


You can also use an ordinary 'for' statement which is useful if you need to know the index of the rows:

for(int i = 0; i < dt.Rows.Count; i++)
{
    DataRow dr = dt.Rows[i];
    // do something with dr

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.