The Data Set

When you create the new data source by using the Data Sources Configuration Wizard, a new dataset called NorthwindDataSet is automatically created for you and added to your project. This dataset gets filled with the data in the database that you chose (the Northwind database), but it is then disconnected from the database. The connection to the database is opened only for the time required to fill the dataset, and then it is closed.

The dataset that is created is a typed dataset. This means that the various types used in the table are known at design time and you can access information about the dataset through the IntelliSense features. The dataset is stored as a schema in your project. You can examine the schema's design-time view when you right-click NorthwindDataSet.xsd in Solution Explorer and select View Designer. Notice that the designer in Figure 7.24 shows a relationship between the tables, something you'll

Figure 7.24. The NorthwindDataSet schema in Visual Studio

look at again later in this chapter. When you add a control from the Data Sources window to the worksheet, the DataSet is added to the component tray, as shown in Figure 7.25.

18

13

20

21

22

23

H 4

► n \She

;tl/sheets'

/ Sheet3 /

p9| NorthwindDataSet ,jij Curr turner rr Table Adapter ^ CustomersBindingSource p9| NorthwindDataSet ,jij Curr turner rr Table Adapter ^ CustomersBindingSource

Figure 7.25. The component tray for data-bound controls on Sheetl The BindingSource

The BindingSource control connects the data source to the controls on your document. You can navigate through records in your data source and sort, filter, and update the data through this BindingSource object. The data is not directly bound from the data source to the control. In our example, the NamedRange and ListObject controls are bound to the CustomerBindingSource, which in turn is bound to the NorthwindDataSet. This lets you simultaneously update each control that is bound to the same binding source. For example, when you move your cursor through the company records in the ListObject control, the contact name in the NamedRange control is automatically updated according to the record that is selected in the ListObject control.

Binding the control to the binding source rather than directly to the data source also enables you to set up data-bound controls before the data in the data table is available—for example, if you want to request a user name and password before displaying data in the document. The CustomerBindingSource is added to the component tray, as shown in Figure 7.25.

0 0

Post a comment