How to retrieve all Rows of the DataTable in C#?

Published on May 30, 2013 by Senthil Kumar

Filed under ADO.NET

Last modified May 30, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 3 (2 votes)

This article have been viewed 10615 times

Below is a sample soucrecode demonstrating how to retrieve all rows of the DataTable to a list in C#.

How to retrieve all Rows of the DataTable in C#?

using System;

using System.Data;

namespace AbundantCode


internal class Program


// Using Foreach to loop through datatable and retreive all rows 
private static void Main(string[] args)


DataTable dt = new DataTable();



DataRow row1 = dt.NewRow();

row1["Name"] = "Abundantcode";

row1["Code"] = "1-1-1";


DataRow row2 = dt.NewRow();

row2["Name"] = "Plenty of sourcecode";

row2["Code"] = "1-1-12";


foreach (DataRow row in dt.Rows)


string Name = row["Name"].ToString();







How to retrieve all Rows of the DataTable in C#?

Leave a Comment


You might be Interested in these Posts

How to read a connection string from web.config file in ASP.NET ?

Assume that you have a connectionstring configured in the web.config file of your ASP.NET applicatio...

How to Turnoff Frame rate counter in UWP App ?

You can turn off the frame rate counter in your Universal Windows Platform (UAP) apps by following t...

How to Clone an Object in JQuery ?

If you are looking at cloning an object in JQuery , you can do that using the jQuery's extend method...