Answer: 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