Databases Reference
In-Depth Information
Note that the XML has simply mapped the dataset as a hierarchy. The first XML ele-
ment, <NewDataSet> , is the dataset name (defaulting to NewDataSet since you don't specify
one). The next element, <products> , uses the data table name (you have only one data
table since you use only one query to populate the dataset), and it's nested inside the
dataset element. The data column elements, <productname> and <unitprice> , are nested
inside this element.
The data for each column appears (as plain text) between the start tag (for example,
<productname> ) and the end tag (for example, </productname> ) for each column element.
Note that the <products> elements represent individual rows, not the whole table. So, the
column elements are contained within the start tag <products> and end tag </products>
for each row.
If you scroll to the bottom of the XML file, you'll find the end tag </NewDataSet> for the
dataset.
Using Data Tables Without Datasets
As we mentioned in our first example, “Populating a Dataset with a Data Adapter,” data
tables can be used without datasets. Most of the time this involves calling the same meth-
ods on data tables that you use for datasets. We'll give one example. You should then be
able to analogize from it for other processing.
n Note Datasets and data tables can also be used without data adapters. Such uses are beyond the scope
of this topic.
Try It Out: Populating a Data Table with a Data Adapter
This example is based on our first example, PopDataSet.cs (Listing 13-1). You'll create
a data table, populate it with a data adapter, and then display its contents.
1. Add a new C# Console Application project named PopDataTable to your
Chapter13 solution. Rename Program.cs to PopDataTable.cs .
2. Replace the code in PopDataTable.cs with the code in Listing 13-10. The lines
changed from Listing 13-1 are highlighted in bold.
Search WWH ::




Custom Search