I used Visual Studio 2008 with Visual Basic.NET for this sample.

  1. Start New website (or web applicaiton) project
  2. In the Server Explorer, add a data connection. (I added a SQL Server database ‘test’ with only one table ‘test’.
  3. Right click on the solution in Solution Explorer and select Add Existing Item…
  4. Add LINQ to SQL Classes (this is a file with .dbml extension)
  5. Double click this file on Solution Explorer - if it is not already in the design view
  6. Drag your table from Server Explorer -> Data Connections to the dbml file
  7. Now take your aspx file. Say Default.aspx
  8. Drag and drop Asp.net GridView control from the Toolbox
  9. Now copy paste the below code in your Page_Load event


Dim db As New DataClassesDataContext()

Dim t = From n In db.tests Select n

GridView1.DataSource = From n In db.tests Select n
GridView1.DataBind()

  1. Now just execute the website (Press F5). It should show a populated grid.

From n In db.tests Select n is the simple LINQ query used to selecting data from your table. It is the equivalent of SELECT * FROM yourdb.yourtable

VN:F [1.1.6_502]
Rating: 5.0/5 (2 votes cast)
Share:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • DotNetKicks
  • LinkedIn
  • Live
  • MySpace
  • StumbleUpon
  • Technorati

Related posts:

  1. Types of Tests in Visual Studio
  2. Write your first SQL Server CLR Stored Procedure
  3. Visual Studio 2010 – my read bits
  4. SQL IN clause in LINQ
  5. LINQ Group : how to