As a database programmer you may love the for..loop, but as .Net programmer you can use many advanced features like Enumerables,Linq etc, which provide ease and peace.
Let’s begin with a DataSet, have many rows.My Products table contain a list of Medicine names. All I want to get the whole data in two line code with the Help of Linq query.
Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language Know More
Adapted from Doc.Microsft.com
Use the AsEnumerable()
AsENumerable method allows you to fetch rows as Enumerable string array, which actually not an array at all. We her try to fetch the rows an variant type variables with a Linq query.
Linq Queryvar enum_names =from products in Product_dataset.Tables[0].AsEnumerable() select
products.Field<string>("name");
Print Result
foreach (string str in enum_names){
Console.WriteLine(str);
}
One thought on “Extract Rows from DataTable using AsEnumerable and Linq Querry”