Free mag vol1 | Page 956

CHAPTER 22  ADO.NET PART II: THE DISCONNECTED LAYER This last example should probably convince you of the usefulness of the DataSet class. Given that a DataSet is completely disconnected from the underlying data source, you can work with an in-memory copy of data and navigate around each table to make any necessary updates, deletes, or inserts without incurring any round trips to the database. After you finish this, you can submit your changes to the data store for processing. The end result is a scalable and robust application.  Source Code You can find the MultitabledDataSetApp project under the Chapter 22 subdirectory. The Windows Forms Database Designer Tools All of the examples thus far have involved a fair amount of elbow grease in the sense that you had to author all data access logic by hand. While you did offload a good amount of this code to a .NET code library (AutoLotDAL.dll) for reuse in later chapters of the book, you still had to create the various objects of your data provider manually before interacting with the relational database. The next task in this chapter is to look at how you use various Windows Forms database designer tools, which can produce a good deal of data access code on your behalf.  Note Windows Presentation Foundation and ASP.NET web projects have similar database designer tools; you’ll look at some of these later in this chapter. One way you can use these integrated tools is to use the designers supported by the Windows Forms DataGridView control. The problem with this approach is that the database designer tools will embed all of the data access code directly into your GUI code base! Ideally, you want to isolate all of this designergenerated code in a dedicated .NET code library, so you can easily reuse your database access logic across multiple projects. Nevertheless, it might be helpful to begin with an examination of how you can use the DataGridView control to generate the required data access code, given that this approach does have some usefulness in small-scale projects and application prototypes. After this point, you will learn how to isolate the same designer-generated code into a third version of AutoLotDAL.dll. Visually Designing the DataGridView The DataGridView control has an associated wizard that can generate data access code on your behalf. Begin by creating a brand-new Windows Forms application project named DataGridViewDataDesigner. Rename the initial form to MainForm.cs using the Solution Explorer, and then add an instance of the DataGridView control (named inventoryDataGridView) to your initial form. When you select your DataGridView control, an inline editor should open to the right-hand side of the control (if not, just click on the small “triangle button” found on the upper right of the control). From the Choose Data Source drop-down box, select the Add Project Data Source link (see Figure 22-14). 902