Free Web Development Online Tutorials, Learn to Code
Learn LINQ with C#- Language Integrated query

How to use LINQ with ADO.NET Objects

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

Learn how to use LINQ with Ado.Net Objects

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 code? The answer is Yes!

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 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;

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 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 was introduced with very initial stage of .Net Framework; 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 objects we can write T-SQL query to work with database LINQ provides common query syntax to work with any type of datasource.

LINQ Tutorial with Examples in C#

Learn LINQ with many real-time examples

Learn LINQ .Net

Linq with Dataset, Datatable Example

linq Interview Questions Answers