How to Create a Strongly Typed DataSet

In this article, we are going to see how to create a Strongly Typed DataSet using the Visual Studio .NET IDE.
 
Follow these steps to create a Strongly Typed DataSet :
  1. In Visual Studio .NET 2008/2010, click File > New > Project.
     
  2. Select your desired programming language and then select the Console Application template.
     
  3. Right-click on the project in Solution Explorer and click Add > New Item. On the Add New Item dialog select DataSet from the items list. Name the DataSet StronglyTypedDataSet.xsd. Click on the Add button to create the DataSet.
     
    DataSet1.gif
     
  4. Now, If you do not already have a Database Connection, create a new one > Open Server Explorer by selecting View > Server Explorer from the main menu. Right-click on the Data Connections node and select Add Connection from the context menu.
     
    DataSet2.gif
     
  5. In the next dialog box, select the SQL Server. In the Add Connection dialog select Server name.
     
    Under Log on to the server, do one of the following:
     
    • Click Use Windows Authentication to use your current Windows user name and password.
    • Click Use SQL Server Authentication and then type your user name and password in the corresponding User Name and Password boxes.
     
    Here we are using log on mode as Windows Authentication.
     
    Under Connect to a database select or enter a database name. We are using the AdventureWorks database. Click on the Test Connection button and then the OK button to create the connection.
     
    DataSet3.gif
     
  6. Now expand the Tables node in Server Explorer for the Data Connection that you just added. Select the Customer (Sales) and CustomerAddress (Sales) tables and drag them onto the DataSet Designer surface.
     
  7. This adds both tables to the strongly typed DataSet. If you don't want all of the columns in a table, expand a table and drag just the columns you need onto the design surface. The designer now shows the two tables together with the data relation between the tables.
     
    DataSet4.gif
     
  8. The strongly typed DataSet is complete and you can now use it.


Similar Articles