locked
Custom conversions for DataSet Merge (untyped to strongly typed)? RRS feed

  • Question

  • Hello,

    I am trying to merge an untyped DataSet into a strongly typed DataSet.

    The two DataSets have the same table and column names, but the column data types are different in some cases -- so, the call to Merge() fails.

    The untyped DataSet actually has the correct values for each column, only the data type is wrong (for example, string instead of double).

    When I was converting this manually, I could simply call Convert.ToDouble(sourceTable["ColumnName"]), and get the right value.  But obviously, Merge() doesn't do this automatically.

    So, can I somehow create a custom converter to pass to Merge(), or is there another way to merge these data sets without going through each table and column manually?

    Thanks
    Monday, November 23, 2009 5:35 PM

Answers

  • You don't say where the data in the untyped DataSet comes from, but if you can change the DataType from string to double before you put data into it, then your Merge will work. Unfortunately, after the DataTable contains data, you can't change a column's DataType.

    Is this something you can do or is putting the data into the DataTable what defines your DataTypes?
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Marked as answer by Yichun_Feng Tuesday, December 1, 2009 1:56 AM
    Saturday, November 28, 2009 10:36 PM

All replies

  • Do both tables have the same primary keys??
    Wednesday, November 25, 2009 5:52 PM
  • You don't say where the data in the untyped DataSet comes from, but if you can change the DataType from string to double before you put data into it, then your Merge will work. Unfortunately, after the DataTable contains data, you can't change a column's DataType.

    Is this something you can do or is putting the data into the DataTable what defines your DataTypes?
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    • Marked as answer by Yichun_Feng Tuesday, December 1, 2009 1:56 AM
    Saturday, November 28, 2009 10:36 PM