How to use ado.net dataset datatable in linq query

Here we learn how to write LINQ query with ado.net dataset, some real-time example of using LINQ in asp.net

Though LINQ was not designed to use with ADO.Net objects;
Because ADO.Net was based on different approach that we have used so far in application development.

But just consider if you have any application already developed using ADO.Net, now can you write LINQ queries on your existing ado.net code? The answer is Yes!

Use LINQ with Ado.Net Objects

In previous tutorial we have already learned about ADO.Net Objects, Now you learn how to write LINQ queries with ADO.Net object like dataset, datatable etc.

linq with ado.net example

Here is the code

var _students = from dt in _ds.Tables[0].AsEnumerable()
where (dt.Field<string>("FullName").StartsWith("A"))
select new
{
    Name = dt.Field<string>("FullName"),
    Address = dt.Field<string>("Address")
};

Now simply assign the collection object to a gridview

gvStudents.DataSource = _students;
gvStudents.DataBind();
Difference between LINQ and ADO.Net

Now you have basic idea about how LINQ works, in LINQ you can query to any data source like SQL, XML, Entity Framework, ADO.Net and more, but Ado.Net works differently where you can execute query using any ado.net objects which can work with any RDBMS like Oracle, SQL etc.

In this section we will try to a comparative overview of Ado.Net and LINQ

Ado.Net LINQ
Ado.net was introduced with very initial stage of .Net Framework; Ado.net is actually upgraded version of Ado component LINQ was introduced later stage with .Net 3.5 release
Supports type checking at run-time; so we can find syntax errors at run-time only. It supports type checking at compile-time , so we can debug and find syntax errors at compile-time.
Apart from Ado.net objects we can write T-SQL query to work with database LINQ provides common query syntax to work with any type of datasource.
 
Linq with Ado.net Dataset: use linq with Datatable Example
LINQ (language integrated query) allow you to write query on database objects like ado.net, entity framework etc, LINQ is type safe, easy to convert database object to list objects and business objects in secure and scalable way.
linq Interview Questions Answers
LINQ C# examples | Join Asp.net MVC Course