data from the data source, the data has to be retrieved into either a DataReader or a dataset (described below). Think of the DataReader as a straw that you use to deliver your Slurpee from the cup to your mouth. The DataReader retrieves the results from the query and allows your application to look at each individual row of data. Once your application is ready, you use the Read method of the DataReader to retrieve the next row of data until all rows have been retrieved. At that point, the connection to the database can be closed.
DataSet object – The dataset is a container for disconnected data. The dataset can hold data in multiple data tables, each data table representing one or more tables from one or more data sources, such as databases, XML files, text files and more. So, one dataset could contain a table from a SQL Server 2005 Express Edition database and an Access database. The data tables and their relations are defined in an XML Schema document called an XSD. Or, developers can define the structure of the data tables (including their columns names and data types, etc.) programmatically.
To extend the Slurpee analogy from the previous section about the DataReader … a DataReader is a straw. A DataSet is another cup that you transfer the Slurpee into. Once your application is finished with the Slurpee, you transfer it back into the original cup. So as you can see, the scope of the DataSet is much larger than that of the DataReader.
Changes to the dataset are recorded in a series of diffgrams, which essentially is a list of changes that your program makes to the dataset – data rows added, edited and deleted from the dataset. These diffgrams are kept until the changes are resolved back into the original data source through the use of the Update method of the associated DataAdapter (more about that object below).
The dataset and its contents are stored in memory for as long as the program keeps a reference to the dataset’s instance. However, it has a unique ability to be persisted (saved) to XML and that XML can be stored into a file or sent over the network through the use of a Web Service. While it might not be apparent why you would want to do that right now, eventually you may face a situation where you need to store (or send the data to another computer for processing) for a prolonged period of time
even when the application that originally created the dataset is
not running. This is a bit advanced, however it provides a great deal of utility for your application design.
DataAdapter object – As briefly noted in the paragraphs about the dataset, the DataAdapter contains a series of command
Supplemental Readings for the Express Edition Videos Copyright © 2005 LearnVisualStudio.NET