The Artima Developer Community
Sponsored Link

.NET Buzz Forum
The 3 Most Obvious and Useful Changes to DataTable and DataSet in .Net 2.0

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Raymond Lewallen

Posts: 312
Nickname: rlewallen
Registered: Apr, 2005

Raymond Lewallen is a .Net developer and Sql Server DBA
The 3 Most Obvious and Useful Changes to DataTable and DataSet in .Net 2.0 Posted: Aug 8, 2005 7:58 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Raymond Lewallen.
Original Post: The 3 Most Obvious and Useful Changes to DataTable and DataSet in .Net 2.0
Feed Title: Raymond Lewallen
Feed URL: /error.htm?aspxerrorpath=/blogs/raymond.lewallen/rss.aspx
Feed Description: Patterns and Practices, OOP, .Net and Sql
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Raymond Lewallen
Latest Posts From Raymond Lewallen

Advertisement

The DataSet and DataTable objects have great improvements in many areas.  The DataRowCollection backing object changing from an ArrayList to a Red-Black tree is a GREAT one!  Some, like what I just mentioned with the DataRowCollection, you can’t do anything about, the enhancement is just there.  Below I have noted what may be the three most often used new features of the DataTable and DataSet objects, and you will have to change your code to use them.

DataSet and DataTable Load Methods

Somewhere floating around, I have some code I’ve always hated.  It’s used to fill a datatable with the data from a datareader.  In 2.0, both DataSet and DataTable have new Load methods which can be used to fill a dataset or datatable with the data from a datareader.  Now we can just do like the following:

DataTable.Load

Dim dr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader()

Dim dt As New System.Data.DataTable

dt.Load(dr)

There are 3 LoadOption enums to be aware that you can use as the second parameter of the DataTable.Load method.

  • LoadOption.OverwriteRow – The incoming values for this row will be written to both the current value and the original value versions of the data for each column.
  • LoadOption.PreserveCurrentChanges (default) – The incoming values for this row will be written to the original value version of each column. The current version of the data in each column will not be changed.
  • LoadOption.Upsert – The incoming values for this row will be written to the current version of each column. The original version of each column's data will not be changed.

DataTable.WriteXml and DataTable.ReadXml

Prior to 2.0, how did you serialize to xml a datatable object?  You created a dataset and then added the datatable to it, then serialized the DataSet.    No longer do you need to do that.  The DataTable object now has its very own WriteXml and ReadXml methods.  Since DataTable now implements an IXmlSerializable interface, you can now use a datatable as a parameter of a XML Web Service.

DataSet and DataTable RemotingFormat

The new RemotingFormat property allows you a new option for setting the serialization format of a DataTable or DataSet.  The two values accepted for this property are SerializationFormat.Xml or SerializationFormat.Binary.  If you are using remoting, Binary is the option you want for improved performance and smaller data chunks.

Read: The 3 Most Obvious and Useful Changes to DataTable and DataSet in .Net 2.0

Topic: MicroISV: Picking a product Previous Topic   Next Topic Topic: Rico

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use