Tutorials and code for ASP.NET 2.0,C#,SQL Server,AJAX tutorials,jQuery  
Home    Articles    Contact Us
 

ASP.NET
AJAX
Interview Questions
Sql Server
Technology News
Tips and Tricks
jQuery

 

LINQ Introduction


Language Integrated Query (LINQ), a new query language feature in .net 3.5.

You can use it to retrieve data from an array or collection or any data source that supports IEnumerable or IQueryable.

Let's see example how to use LINQ in string array.We have string array of country like this,

Dim countries As String() = {"Australia", "Brazil", "China", "Japan", "India", "United States", "United Kingdom"}
Dim data = From country In countries Where country.StartsWith("Uni") Select country.ToUpper
Response.Write("Country List</br">")
For Each country As String In data
Response.Write(country & "</br">")
Next

Here, you have only change "LINQ Query" with query that discuss below.

==> By using LINQ you can retrive data from array. Below LINQ equivalent to SELECT * statement of SQL Server.

From country In countries Select country

==> You can also use conditional statement in array to get data.To retrive country list that have string length less than 6.

From country In countries Where country.Length < 6 Select country

==> You can also sort an array Ascending/Descending.

From country In countries Order By country Descending Select country

==> To retrive Country name that start with "UNI" and country name in Upper case.

From country In countries Where country.StartsWith("Uni") Select country.ToUpper

Here, I have explain how use LINQ.


User Comments:




Post Your Comment :


Name
Email:
Comment:

Home | Contact Us

© 2008-09 TechnoReader.com. All rights reserved.