LINQ To SQL Selecting mulitple fields in a database table
By bryan tugade
We can select multiple fields in a given database tables using Linq to sql. I use AdventureWorks as my database in this sample app and to show you how it works i bind the results in gridview control.
Partial Public Class WebForm1
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim adventureContext = New adventureWorks()
Dim xemployee = (From employee In adventureContext.Employees Select employee.Title, employee.MaritalStatus, employee.VacationHours)
GridView1.DataSource = xemployee
Catch ex As Exception
You can add specific fields that you want to show in the result in this line of code.
Dim xemployee = (From employee In adventureContext.Employees Select employee.Title, employee.MaritalStatus, employee.VacationHours) ' add fields here...
here's the result
That's it! Happy Coding. : )
In C#, we can select and deselect checkbox in gridview in onPostback event of checkbox in gridview header.
Have you try to transfer your data fro SQL Express to Microsoft office excel? What if your company wants you to get all the data from
your database and put it in excel. Theres two way i know how to do it. Here it is.
We can filter data using dataview.
This snippet shows how to connect to SQLExpress and execute stored procedure.
Assuming that you need to create an application that needs to transfer data from sql server to microsoft excel. The first thing you need to do is to find a way to connect to sql server. We can do this by using visual basic application.
LINQ To SQL Selecting mulitple fields in a database table (1737 Views)