15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

XMl <strong>and</strong> aDo.neT ❘ 933<br />

ReadXml() has an XmlReadMode parameter. ReadXml() has a few more options in the XmlReadMode, as<br />

shown in the following table.<br />

Value<br />

Auto<br />

DiffGram<br />

Fragment<br />

IgnoreSchema<br />

InferSchema<br />

ReadSchema<br />

desCriPTion<br />

Sets the XmlReadMode to the most appropriate setting. If the data is in DiffGram format,<br />

DiffGram is selected. If a schema has already been read, or an inline schema is detected,<br />

then ReadSchema is selected. If no schema has been assigned to the DataSet, <strong>and</strong> none<br />

is detected inline, then IgnoreSchema is selected.<br />

Reads in the DiffGram <strong>and</strong> applies the changes to the DataSet.<br />

Reads documents that contain XDR schema fragments, such as the type created by SQL<br />

Server.<br />

Ignores any inline schema that may be found. Reads data into the current DataSet<br />

schema. If data does not match DataSet schema, it is discarded.<br />

Ignores any inline schema. Creates the schema based on data in the XML document. If a<br />

schema exists in the DataSet, that schema is used, <strong>and</strong> extended with additional columns<br />

<strong>and</strong> tables if needed. An exception is thrown if a column exists but is of a different data<br />

type.<br />

Reads the inline schema <strong>and</strong> loads the data. Will not overwrite a schema in the DataSet<br />

but will throw an exception if a table in the inline schema already exists in the DataSet.<br />

There is also the ReadXmlSchema() method. This reads in a st<strong>and</strong>alone schema <strong>and</strong> creates the tables,<br />

columns, <strong>and</strong> relations. You use this if your schema is not inline with your data. ReadXmlSchema() has the<br />

same four overloads: a string with filename <strong>and</strong> pathname, a Stream-based object, a TextReader-based<br />

object, <strong>and</strong> an XmlReader-based object.<br />

To show that the data tables are being created properly, we iterate through the tables <strong>and</strong> columns <strong>and</strong><br />

display the names in the text box. You can compare this to the database <strong>and</strong> see that all is well. The last<br />

foreach loops perform this task. Figure 33-6 shows the output.<br />

figure 33-6<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!