CHAPTER 22 ADO.NET PART II: THE DISCONNECTED LAYER
useful (if not, remember that Visual Studio will autogenerate a good deal of the required code using
various database designer tools, as you will see later).
Implementing GetAllInventory()
Now that your data adapter is ready to go, the first method of your new class type will use the Fill()
method of the SqlDataAdapter object to fetch a DataTable representing all records in the Inventory table
of the AutoLot database, like so:
public DataTable GetAllInventory()
{
DataTable inv = new DataTable("Inventory");
dAdapt.Fill(inv);
return inv;
}
Implementing UpdateInventory()
The UpdateInventory() method is simple, as shown here:
public void UpdateInventory(DataTable modifiedTable)
{
dAdapt.Update(modifiedTable);
}
Here, the data adapter object examines the RowState value of each row of the incoming DataTable.
Based on this value (e.g., RowState.Added, RowState.Deleted, or RowState.Modified), the correct
command object is leveraged behind the scenes.
Setting Your Version Number
Great! At this point, the logic of the second version of your data access library is complete. You are not
required to do so, but set the version number of this library to 2.0.0.0, just for good housekeeping. As
described in Chapter 14, you can change the version of a .NET assembly by double-clicking the
Properties node of your Solution Explorer, and then clicking the Assembly Information... button located
in the Application tab. In the resulting dialog box, set the Major number of the Assembly Version to the
value of 2 (see Chapter 14 for more details). After you do this, recompile your application to update the
assembly manifest.
Source Code You can find the AutoLotDAL (Version Two) project under the Chapter 22 subdirectory.
Testing the Disconnected Functionality
At this point, you can build a front end to test your new InventoryDALDisLayer class. Once again, you will
use the Windows Forms API to display your data on a graphical user interface. Create a new Windows
Forms application named InventoryDALDisconnectedGUI and change your initial Form1.cs file to
894