C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Introduction to LINQ to SQL


Posted Date: 29 Jun 2009    Resource Type: Articles    Category: .NET Framework
Author: ManigandanMember Level: Gold    
Rating: 1 out of 5Points: 15



This article provides an introduction to employing LINQ to SQL within a Windows Forms application.

Let start the LINQ with simple Example,
This is an example of a very simple LINQ to SQL statement:

public void SimpleQuery()

{

DataClasses1DataContext dc = new DataClasses1DataContext();



var q =
from a in dc.GetTable()

select a;



dataGridView1.DataSource = q;

}

In the example, an instance of the data context is created and then a query is formed to get all of the values in the table.
once the query runs, the result is used as the data source of a datagridview control and the results are displayed in the grid.

Now We can try this LINQ by using Where Clause,

public void SimpleQuery2()

{

DataClasses1DataContext dc = new DataClasses1DataContext();

var q =
from a in dc.GetTable()

where a.CustomerID.StartsWith("A")

select a;

dataGridView1.DataSource = q;

}


Now we can Try using the ORDER BY Query in LINQ:

public void SimpleQuery3()

{

DataClasses1DataContext dc = new DataClasses1DataContext();



var q =

from a in dc.GetTable()

where a.CustomerID.StartsWith("A")

orderby a.OrderDate ascending

select a;

dataGridView1.DataSource = q;
}




The article shows some simple examples of LINQ to SQL,
from it you can see how easy it is to query against single and related tables and to write filtered queries.



Responses

Author: Prasoon Kumar    29 Jun 2009Member Level: Silver   Points : 1
Hi
Good one !!

There are few keywords/clauses that are not supported across

DataSet while querying dataset.


it is not related to LINQ to SQL but to LINQ to OBJECTS.



Regards
Prasoon


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Introduction to LINQ to SQL  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Copy selective columns of data table to another datatable - VB.NET
Previous Resource: 3 Musketeers: - Model, View and Controller using ASP.NET MVC – Part 2
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use