Microsoft Visual C#.NET 2003 Kick Start
The dataset acts as a local repository for your data, and it'll be the target of our data operations when we retrieve data from a data provider in a few pages. As you know, you can use the Fill method of a data adapter to fill datasets with data, and if that dataset is bound to controls, those controls will display that new data automatically. You can find the significant public properties of DataSet objects in Table 10.16, their significant methods in Table 10.17, and their significant events in Table 10.18. Table 10.16. Significant Public Properties of DataSet Objects
Table 10.17. Significant Public Methods of DataSet Objects
Table 10.18. Significant Public Events of DataSet Objects
Datasets can be typed or untyped usually, they're typed, which means that C# will keep track of the data type of each field, and will object if you try to assign data of the wrong type to a field. ADO.NET uses XML to transport dataset data, and typed datasets hold their type information in XML schemas.
Note also that if you've bound a dataset to controls in your application, the user can edit the data that appears in those controls. When the user does so, the data in the dataset is also changedbut not the data in the underlying data store that the data was originally fetched from. You can determine which rows have been changed with the dataset's GetChanges method, and when you use the data adapter's Update method, those changes are sent back to the underlying database in the data provider you're working with. The data provider might make some additional changes, including updating fields that hold calculated values, and return a new dataset. In that case, you can merge those new fields into a dataset using the dataset's Merge method. Then you can use the AcceptChanges method in the dataset to accept the changes or the RejectChanges method to cancel the changes. It's time for some codinglet's see all this in action. Our first example, ch10_01, creates its own connection, command, and data adapter objects, and uses them to fill a dataset in code. |