LINQ TO SQL:
LINQ to SQL is a useful tool for developers who do not require mapping to a conceptual model. By using LINQ to SQL, you can use the LINQ programming model directly over existing database schema. LINQ to SQL enables developers to generate .NET Framework classes that represent data. Rather than mapping to a conceptual data model, these generated classes map directly to database tables, views, stored procedures, and user-defined functions. With LINQ to SQL, developers can write code directly against the storage schema using the same LINQ programming pattern as in-memory collections and the DataSet, in addition to other data sources such as XML. Now we will show an example to Select,Update,Insert and Display data from SQL Tables using LINQ. 1.Go to Visual Studio->New WebSite/New Windows Project. 2.Go to Project-->AddWindowsForm/WebForm-->LINQ to SQL Classes-->Nameoffile(your choice).
3.The new file will have an extension of dbml standing for database manipulation language. 4.To connect to the database Go to-->Tools-->Connect to database-->Add Connection as follows:
5.Select the name of your Server, and the name of the database where your required table resides, as shown above.Then press the Test Connection button at the bottom of the window, it displays the Test conncetion succeeded message.
6.Drag and drop the table (EmpList in this example) from the database exploer on to the server explorer area as shown in figure below:
7.Go to the Design page and add a GridView control and also a Button named DISPLAY.
8. Write the following code by double clicking the display button.
9.In the code above, we first declare a datacontext object named dc. Then we acquire the data from Emplist table and assign it to the datasource property of GridView.We later bind the data to the Gridview to display it on the webpage. 10.Now we run the program and the output is displayed in the web page as follows: