CHAPTER 22 ADO.NET PART II: THE DISCONNECTED LAYER
Figure 22-23. A customized data adapter that operates on the strongly typed DataSet and DataTable
The autogenerated InventoryTableAdapter type maintains a collection of SqlCommand objects (which
you can access using the CommandCollection property), each of which has a fully populated set of
SqlParameter objects. Furthermore, this custom data adapter provides a set of properties to extract the
underlying connection, transaction, and data adapter objects, as well as a property to obtain an array
representing each command type.
Completing the Windows Forms Application
If you examine the Load event handler of the form-derived type (in other words, if you view the code for
MainForm.cs and locate the MainForm_Load() method) you will find that the Fill() method of the custom
table adapter is called upon startup, passing in the custom DataTable maintained by the custom DataSet.
private void MainForm_Load(object sender, EventArgs e)
{
this.inventoryTableAdapter.Fill(this.inventoryDataSet.Inventory);
}
You can use this same custom data adapter object to update changes to the grid. Update the UI of
your form with a single Button control (named btnUpdateInventory). Next, handle the Click event and
author the following code within the event handler:
912