Back to VSLive! San Francisco Show Daily Home
Get a Grip on the DataSet
Control how DataSet XML is written, and load multiple tables into the DataSet.
by Jackie Goldstein
VSLive! San Francisco, February 12, 2003
Note: Jackie Goldstein is presenting "The DataSet Unplugged" at VBITS San Francisco, Wednesday, February 12. These tips are from that session.
Control How DataSet XML is Written
When using the DataSet's WriteXml method to write DataSet data contents, the optional parameter XmlWriteMode specifies whether to write the data in the DiffGram format and whether to include an inline schema with the data. But you can use two other properties to control the format of the saved XML. The first is the ColumnMapping property of the DataColumn object, which specifies whether the WriteXml method hides the column, or writes the column as an element, attribute, or simple text. The other property that you should pay attention to is the Nested property of the DataRelation object. This property specifies whether records from the child table in a parent-child relation are nested within the related parent table records when being written by WriteXml.
Load Multiple Tables Into the DataSet
One way to efficiently load multiple database tables into the DataSet in a single trip to the server: Execute a batch of multiple statements. For SQL Server, batch commands are separated by a semi-colon. If the CommandText property of a SqlDataAdapter's SelectCommand is set to:
"select * from authors ; select * from titles"
then the DataAdapter's Fill method will execute the statement in a single trip to the server and fill two tables in the DataSet.
About the Author
Jackie Goldstein is an independent consultant specializing in consulting, training, and development with Microsoft tools and technologies. He has almost 20 years of experience developing and managing software applications in the U.S. and Israel, and is experienced at helping companies evaluate and integrate new technologies. Jackie is the MSDN Regional Director for Israel, the founder of the Israel VB User Group, and a featured speaker at international developer events. He has recently co-authored Database Access with Visual Basic .NET (Addison-Wesley, ISBN 0-67232-3435). Reach Jackie at Jackie@renaissance.co.il.
Back to top
|