Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Creating a Typed DataSet

In this section, we will create a Web application that includes a Typed DataSet with the help of Visual Studio.NET. (It is also possible to create Typed DataSets by using command-line tools because VS.NET also uses nearly the same tools and techniques behind the scene.)

First, create a new project in Visual Studio.NET. (See Figure 1.) (We're creating an ASP.NET project so that later we can play a little bit with a DataGrid and a Typed DataSet.)

Figure 1Figure 1 Create a new project.

Name the project TypedDS, which reflects the Typed DataSet. This project would be accessible with http://localhost/TypedDS.

Right-click the solution and choose Add, Add New Item. (See Figure 2.)

Figure 2Figure 2 Creating a Typed DataSet.

Select the DataSet item in the right pane of the Add New Item window, and name this DataSet as EmployeesTDS.xsd.

We have to do a bit more to make it a true Typed DataSet, and that is to add our tables to the DataSet. We can have multiple tables in our DataSet, as well as relations, constraints, and so on. To maintain the simplicity of the article, however, we will get only one table, Employees, from the Northwind database for our DataSet.

Open your Server Explorer by choosing View, Server Explorer from the main menu of Visual Studio.NET. Click the instance of your local SQL Server and Choose Employees Table, as shown in Figure 3 (in the figure, rahul is the name of my local SQL server.).

Figure 3Figure 3 Inserting table(s) into a Typed DataSet.

Now drag and drop the Employees table onto the surface of EmployeesTDS.xsd. You will get a picture like Figure 4

Figure 4Figure 4 View after inserting the Employees table.

If desired, we can insert multiple tables in the same way and set relations, constraints, and so on. (These may be covered in another article.)

Now we are done with our Typed DataSet. (If you are interested in the XML implementation of the Typed DataSet, click the XML at the bottom of the EmployeesTDS.xsd window. Here you will find the real work done behind the scenes.) Compile the application by choosing Build, Build Solution from the main menu.

Now we can use our Typed DataSet as a normal DataSet by creating its instance.

  • + Share This
  • 🔖 Save To Your Account