none
Update table adapter after using dataset.merge method RRS feed

  • Question

  • I am merging two datatables together and after which wish to update the datasource, in this case SQL Server.  The problem I am having is that after using the merge method no changes are recognized?  Is this possible to do?

    David Dye
    • Moved by Martin Xie - MSFT Friday, October 30, 2009 3:13 AM Move it to ADO.NET DataSet forum for better support. (From:Visual Basic Language)
    Thursday, October 29, 2009 4:03 PM

Answers

  • Hello David,


    DataSet.Merge has serveral overloaded methods. You can take a look at the ones that has a bool type parameter, PreserveChanges.

    http://msdn.microsoft.com/en-us/library/system.data.dataset.merge.aspx
    http://msdn.microsoft.com/en-us/library/06t089d7.aspx

    Actually, 
    "When you pass a DataSet, DataTable, or DataRow array to the Merge method, you can include optional parameters that specify whether or not to preserve changes in the existing DataSet, and how to handle new schema elements found in the incoming data. The first of these parameters after the incoming data is a Boolean flag, PreserveChanges, which specifies whether or not to preserve the changes in the existing DataSet. If the PreserveChanges flag is set to true, incoming values do not overwrite existing values in the Current row version of the existing row. If the PreserveChanges flag is set to false, incoming values do overwrite the existing values in the Current row version of the existing row. If the PreserveChanges flag is not specified, it is set to false by default. For more information about row versions, see Row States and Row Versions (ADO.NET).

    When PreserveChanges is true, the data from the existing row is maintained in the Current row version of the existing row, while the data from the Original row version of the existing row is overwritten with the data from the Original row version of the incoming row. The RowState of the existing row is set to Modified. The following exceptions apply:

    • If the existing row has a RowState of Deleted, this RowState remains Deleted and is not set to Modified. In this case, the data from the incoming row will still be stored in the Original row version of the existing row, overwriting the Original row version of the existing row (unless the incoming row has a RowState of Added).

    • If the incoming row has a RowState of Added, the data from the Original row version of the existing row will not be overwritten with data from the incoming row, because the incoming row does not have an Original row version.

    When PreserveChanges is false, both the Current and Original row versions in the existing row are overwritten with the data from the incoming row, and the RowState of the existing row is set to the RowState of the incoming row. The following exceptions apply:

    • If the incoming row has a RowState of Unchanged and the existing row has a RowState of Modified, Deleted, or Added, the RowState of the existing row is set to Modified.

    • If the incoming row has a RowState of Added, and the existing row has a RowState of Unchanged, Modified, or Deleted, the RowState of the existing row is set to Modified. Also, the data from the Original row version of the existing row is not overwritten with data from the incoming row, because the incoming row does not have an Original row version. " 

    •  

    See more information from,
    http://msdn.microsoft.com/en-us/library/aszytsd8.aspx
     
    Hope this helps!

    Ji Zhou

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by David Dye Friday, October 30, 2009 11:42 AM
    Friday, October 30, 2009 6:32 AM
    Moderator

All replies

  • Hello David,


    DataSet.Merge has serveral overloaded methods. You can take a look at the ones that has a bool type parameter, PreserveChanges.

    http://msdn.microsoft.com/en-us/library/system.data.dataset.merge.aspx
    http://msdn.microsoft.com/en-us/library/06t089d7.aspx

    Actually, 
    "When you pass a DataSet, DataTable, or DataRow array to the Merge method, you can include optional parameters that specify whether or not to preserve changes in the existing DataSet, and how to handle new schema elements found in the incoming data. The first of these parameters after the incoming data is a Boolean flag, PreserveChanges, which specifies whether or not to preserve the changes in the existing DataSet. If the PreserveChanges flag is set to true, incoming values do not overwrite existing values in the Current row version of the existing row. If the PreserveChanges flag is set to false, incoming values do overwrite the existing values in the Current row version of the existing row. If the PreserveChanges flag is not specified, it is set to false by default. For more information about row versions, see Row States and Row Versions (ADO.NET).

    When PreserveChanges is true, the data from the existing row is maintained in the Current row version of the existing row, while the data from the Original row version of the existing row is overwritten with the data from the Original row version of the incoming row. The RowState of the existing row is set to Modified. The following exceptions apply:

    • If the existing row has a RowState of Deleted, this RowState remains Deleted and is not set to Modified. In this case, the data from the incoming row will still be stored in the Original row version of the existing row, overwriting the Original row version of the existing row (unless the incoming row has a RowState of Added).

    • If the incoming row has a RowState of Added, the data from the Original row version of the existing row will not be overwritten with data from the incoming row, because the incoming row does not have an Original row version.

    When PreserveChanges is false, both the Current and Original row versions in the existing row are overwritten with the data from the incoming row, and the RowState of the existing row is set to the RowState of the incoming row. The following exceptions apply:

    • If the incoming row has a RowState of Unchanged and the existing row has a RowState of Modified, Deleted, or Added, the RowState of the existing row is set to Modified.

    • If the incoming row has a RowState of Added, and the existing row has a RowState of Unchanged, Modified, or Deleted, the RowState of the existing row is set to Modified. Also, the data from the Original row version of the existing row is not overwritten with data from the incoming row, because the incoming row does not have an Original row version. " 

    •  

    See more information from,
    http://msdn.microsoft.com/en-us/library/aszytsd8.aspx
     
    Hope this helps!

    Ji Zhou

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by David Dye Friday, October 30, 2009 11:42 AM
    Friday, October 30, 2009 6:32 AM
    Moderator
  • Ji,
         Thank you so much for the detailed answer.

    David Dye
    Friday, October 30, 2009 11:42 AM