Geeks With Blogs

News My Blog has been MOVED to
Michael Freidgeim's OLD Blog My Blog has been MOVED to

In my previous post I described a problem when Typed Dataset merged into un-typed dataset.
I've reviewed  the code of Dataset.Merge using Reflector and found, that if table doesn't exist in the current dataset,  Table.Clone is called(in internal private DataTable Merger.MergeSchema function) to add a new table to the dataset.Unfortunately,they do not call virtual Table.Clone() method, that is overridden by the derived typed dataset, but use

internal DataTable Clone(DataSet cloneDS),which can't be overridden by the derived class.

Dataset.Merge should invoke virtual Table.Clone for copied tables.

I've posted this as a suggestion to Microsoft.


Posted on Saturday, November 11, 2006 8:32 AM .Net Framework | Back to top

Comments on this post: Dataset.Merge should invoke virtual Table.Clone for copied tables.

# re: Dataset.Merge should invoke virtual Table.Clone for copied tables.
Requesting Gravatar...
Hi Michael,

Yesterday I got the same problem while tesing my application on .NET Framework 2.0. All was fine on 1.1 but on 2.0 it went down with InvalidArgument exception. Thanks for your post, it's clarified the problem.

I've found a simple work-around:

The old (.NET 1.1) code:

DataSet newDataSet = new DataSet();
newDataSet.Merge(typedDataSet.Tables[0], false, MissingSchemaAction.Add);

The new code (compatible with 2.0):

DataSet newDataSet = typedDataSet.Clone();
newDataSet.Merge(typedDataSet.Tables[0], false, MissingSchemaAction.Add);

Or you can use

DataSet newDataSet = new DataSet();
newDataSet.Merge(typedDataSet.Tables[0], false, MissingSchemaAction.Add);

In my case I need to merge only one table from typedDataSet to newDataSet so I've used the last way.

Dmitry [dmsergeev (at no spam) mail (dot) ru]
Left by Dmitry on Nov 29, 2006 5:57 PM

Your comment:
 (will show your gravatar)

Copyright © Michael Freidgeim | Powered by: