LINQ - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

LINQ SQL

LINQ to SQL

shape Introduction

In this article, I am going to explain "How to connect LINQ to SQL". Please follow the below steps to work with the LINQ to SQL.
  • Open the SQL server and create tables as shown in the below figure.

shape Description

  • Create a new windows forms application in Visual Studio.
  • Add the connection using Server Explorer.
  • Now, Go to Solution Explorer and then right click on the Application.
  • Click on the Add->New Item. Then the following window will appear.
  • Select the Data and then LINQ to SQL.
  • Give the Name as you want like Employee.dbml
  • Go to Server Explorer and then expand the tables.
  • Select the tables and drag the tables on to the empty screen.
  • Interanally it will generate two classes.
    • Employee DataContext Class
    • EMP Details Class with the TableName
  • Go to code window and then write the code for the following design.
  • Write the following code in the Employee.aspx.cs
[csharp] [/csharp]
  • Now, Run the Application. Then you will get all the employees who are males in a gridview.
  • This is the process to work with LINQ to SQL.