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

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.
 

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted @ Saturday, November 11, 2006 8:32 AM
Print

Comments on this entry:

# re: Dataset.Merge should invoke virtual Table.Clone for copied tables.

Left by Dmitry at 11/29/2006 5:57 PM
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.Tables.Add(typedDataSet.Tables[0].Clone());
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.

Regards,
Dmitry [dmsergeev (at no spam) mail (dot) ru]

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910