Using Data Sources with the DataGridView Control (Page 1 of 5 )
Last week, we began our discussion of using data sources with databases in Visual Studio 2005. This week, we conclude the tutorial. This article, the second of two parts, is excerpted from chapter 14 of the book
Murach's Visual Basic 2005, written by Anne Boehm (Murach, 2006; ISBN: 1890774383).
The schema file created by the Data Source Configuration Wizard
After you complete the Data Source Configuration Wizard, the new data source is displayed in the Data Sources window you saw in figure 14-1. In addition to this data source, Visual Studio generates a file that contains the schema for the DataSet class. This file defines the structure of the dataset, including the tables it contains, the columns that are included in each table, the data types of each column, and the constraints that are defined for each table. It is listed in the Solution Explorer window and is given the same name you specified for the dataset in the last step of the Data Source Configuration Wizard with a file extension of xsd. In figure 14-5, for example, you can see the schema file named MMABooksDataSet.xsd. As you’ll learn later in this chapter, you can view a graphic representation of this schema by double-clicking on this file.
Beneath the schema file, the Solution Explorer displays the file that contains the generated code for the DataSet class. In this figure, this code is stored in the MMABooksDataSet.Designer.vb file. When you create bound controls from the data source as shown in this chapter, the code in this class is used to define the DataSet object that the controls are bound to. Although you may want to view this code to see how it works, you shouldn’t change it. If you do, the dataset may not work correctly.
By the way, you should know that a dataset that’s created from a dataset class like the one shown here is called a typed dataset. The code in the dataset class makes it possible for you to refer to the tables, rows, and columns in the typed dataset using the simplified syntax you’ll see in this chapter and the next chapter. In contrast, in chapter 16, you’ll learn how to create an untyped dataset. As you’ll see, you create this type of dataset using code.
A project with a dataset defined by a data source

Description
- After you create a data source, it’s displayed in the Data Sources window. Then, you can use it to create bound controls as shown in this chapter.
- Visual Studio also generates a file that contains the schema for the dataset defined by the data source. This file appears in the Solution Explorer and has a file extension of xsd. It defines the structure of the dataset, including the tables it contains, the columns in each table, the data types of each column, and the constraints for each table.
- Subordinate to the schema file is a file that contains the generated code for the dataset class. Visual Studio uses this class to create a dataset object when you add the data source to a form.
Note
- To see the files that are subordinate to the schema file, click the Show All Files button at the top of the Solution Explorer. Then, expand the node for the schema file.
Figure 14-5. The schema file created by the Data Source Configuration Wizard
How to use a data source with a DataGridView control
Once you’ve created a data source, you can use a DataGridView control to display a grid that can be used to add, update, or delete that data. The DataGridView control is new to .NET 2.0 and has been designed to work with data sources. Although this control provides much of the same functionality as the DataGrid control that was available with previous versions of .NET, it also contains some significant enhancements.
Next: How to generate a DataGridView control from a data source >>
More Visual Basic.NET Articles
More By Murach Publishing
|
This article is excerpted from chapter 14 of the book Murach's Visual Basic 2005, written by Anne Boehm (Murach, 2006; ISBN: 1890774383). Check it out today at your favorite bookstore. Buy this book now.
|
|