Showing posts with label DataTable. Show all posts
Showing posts with label DataTable. Show all posts

Wednesday, May 11, 2011

Why Field is required for DataTable Linq

Here is one good blog for the same Click here

E.g

DataTable dt = new DataTable();

//Adding Columns and names
dt.Columns.Add("ID" ,typeof(int));
dt.Columns.Add("Name",typeof(string));

//Adding Rows and values

dt.Rows.Add(1,"anish");
dt.Rows.Add(2,"marokey");
dt.Rows.Add(2,"varghese");

//querying the result where ID is 2
var result = from p in dt.AsEnumerable()
where p.Field("ID") == 2
select p.Field("Name");

Add Columns and Name to DataTable

Here is a simple example to add values to DataTable

DataTable dt = new DataTable();

//Adding Columns and names
dt.Columns.Add("ID" ,typeof(int));
dt.Columns.Add("Name",typeof(string));

//Adding Rows and values

dt.Rows.Add(1,"anish");
dt.Rows.Add(2,"marokey");