Extreme beginner’s LINQ sample in VB.NET
Filed in DOTNET on Dec.18, 2008
I used Visual Studio 2008 with Visual Basic.NET for this sample.
- Start New website (or web applicaiton) project
- In the Server Explorer, add a data connection. (I added a SQL Server database ‘test’ with only one table ‘test’.
- Right click on the solution in Solution Explorer and select Add Existing Item…
- Add LINQ to SQL Classes (this is a file with .dbml extension)
- Double click this file on Solution Explorer - if it is not already in the design view
- Drag your table from Server Explorer -> Data Connections to the dbml file
- Now take your aspx file. Say Default.aspx
- Drag and drop Asp.net GridView control from the Toolbox
- 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()
- 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
Related posts:























Leave a Reply
You must be logged in to post a comment.