Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
HI all, how to bind values in dataset using Linq to dataset. Need sample code in asp.net.
Posted

There are really nice samples on MSDN:

LINQ to DataSet Samples[^]

101 C# LINQ Samples[^]
or
101 Visual Basic LINQ Samples[^]

Calin
 
Share this answer
 
XML
DataSet ds = new DataSet();
ds.Locale = CultureInfo.InvariantCulture;
FillDataSet(ds);

DataTable products = ds.Tables["Product"];

IEnumerable<DataRow> query =
    from product in products.AsEnumerable()
    select product;

Console.WriteLine("Product Names:");
foreach (DataRow p in query)
{
    Console.WriteLine(p.Field<string>("Name"));
}
 
Share this answer
 
You'll need to add a reference to
C#
System.Data.DataSetExtensions


Then your DataTable will have an extension method AsEnumerable(). You can use this to then run LINQ queries on the rows. There's an example that shows how to use linq with datasets using C#.
 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900