Disconnected Data via ADO.NET and DataSets
During the beta for Windows 2000, Microsoft released a very exciting part of COM+ that would allow for the manipulation of disconnected data in memory. This technologycalled IMDB (in-memory database)promised to solve a host of problems associated with distributed database applications, as it meant that an application could connect to a data source, retrieve into memory the necessary data, disconnect from the data source, and then read from and manipulate the in-memory representation of the data without incurring constant round-trips to the data store or keeping the connection alive for long periods of time, thereby locking crucial data. Once finished with its work, the application could then connect the IMDB back to its data store and synchronize any changes that were made. Unfortunately, just as Release Candidate 2 for the Windows 2000 operating system was being released, Microsoft announced that for various reasons IMDB just wasn't ready for prime time and would not ultimately be a part of the Windows 2000 final release.
While many of us were very disappointed by this decision, what we could not have known at the time was that IMDB was taking a slightly differentand more powerfulform and being included into something then called NGWS (Next Generation Windows Services)what we now know as .NET. This .NET incarnation of an in-memory, disconnected data model is only one part of the overall ADO.NET data access layer. However, as MFC developers, we have plenty of data access technologies to pick from (MFC database classes, ODBC, OLEDB, ADO, DAO, etc.). Therefore, this chapter will focus on the aspects of ADO.NET that we do not havespecifically the various classes that support the original concepts of IMDB.
The chapter begins with a section illustrating the basic terminology and classes specific to ADO.NET and disconnected data as well as the basics of constructing those objects and connecting to a data source. From there, you'll begin a section illustrating how to perform basic database operations (creating, reading, updating, and deleting of records). Included in that section are tips on handling the common issues of dealing with disconnected data and auto-increment primary keys, and how to specify primary key information for untyped datasets. The section ends with a fully functional MFC maintenance application using the ADO.NET against a sample database. At this point, you'll be fairly comfortable with the basics of reading and writing data to a disconnected data table. I'll then illustrate several techniques for reading and writing data in batch in order to keep round trips to the data server to a minimum and dramatically speed up insert operations. One of the key benefits of an IMDB is its support of the ability to search, sort, and filter data once it's been retrieved. Therefore, the next section illustrates how to accomplish these tasks as well as how to create multiple filtered views on a single dataset. Finally, the chapter ends with a section on generating strongly typed datasets, using them in an MFC application, and the pros and cons of using untyped vs. typed datasets.