Getting all data from a table
In the previous “how to add database to project” post, you see we add a database, now here we are querying on that database.
This is the connection string which let you connect to the server:
· Data Source = "Your Server Name"
· Initial Catalog = "The name of your database"
· Integrated Security = "true" for getting your credentials automatic to your current login account in windows, in this way you don't have to use user id and password while establishing connection with SQL server.
The following is the class generated when you add "Linq to SQL classes" to project, which takes an argument of connection string:
The following query is a simple query which gets all the data from Customer table from database:
Customer is the table from database but here when you querying on it using dc.Customers you see, Customer here becomes Customers the additional "s" is automatic attached. If there is Item table in your database then here will be Items.