How to loop through all rows of the DataTable?

 Posted by Raja on 4/14/2008 | Category: C# Interview questions | Views: 14758

You can do this in more than one way but ForEach loop is much better than any other way in terms of cleanliness of the code or performance.

ForEach loop
foreach (DataRow row in dTable.Rows)

yourvariable = row["ColumnName"].ToString();

For loop

for (int j = 0; j< dTable.Rows.Count; j++)
yourvariable = dTable.Rows[j]["ColumnName"].ToString()l

Asked In: Many interviews | Alert Moderator 

Comments or Responses

Login to post response