Try Accessing a DataTable is the easiest way , which can help you get the perfect idea for accessing a DataTable, DataSet using Linq ...
Consider the following example: suppose a DataTable , as shown below.
DataTable ObjDt = new DataTable("List"); ObjDt.Columns.Add("WorkName", typeof(string)); ObjDt.Columns.Add("Price", typeof(decimal)); ObjDt.Columns.Add("Area", typeof(string)); ObjDt.Columns.Add("Quantity",typeof(int)); ObjDt.Columns.Add("Breath",typeof(decimal)); ObjDt.Columns.Add("Length",typeof(decimal));
Here is the DatTable code, here we assume that there is some data in this DataTable, and we need to bind the Grid representation of a particular one by processing some data, as shown below.
Area | Quantity | Breath | Length | Price = Quantity * Breath * Length
Then we need to run the following query, which will give us the exact result as necessary.
var data = ObjDt.AsEnumerable().Select (r => new { Area = r.Field<string>("Area"), Que = r.Field<int>("Quantity"), Breath = r.Field<decimal>("Breath"), Length = r.Field<decimal>("Length"), totLen = r.Field<int>("Quantity") * (r.Field<decimal>("Breath") * r.Field<decimal>("Length")) }).ToList();
We just need to assign this data variable as a data source.
Using this simple Linq query, we can get all of our solutions, as well as complete all other LINQ queries with this ...
Sagar upadhyay
source share