CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2004
    Posts
    5

    Question Determining whether DataRow values have changed

    I have an application with a strongly typed Dataset which I populate and then transform the rows in the DataTable into objects used in my application. The application then updates the objects and I call code to update the appropriate DataRows before submitting the updates to the table.

    I originally wrote the method to update the DataRow to update each column in the row using the value in the object passed in. This however causes the RowState of the DataRow to change from Unchanged to Modified even if the value has not changed. Therefore I have logic to check the values in the DataRow with the value in the object and only update if there is a change, this logic incorporates checking for null values also.

    Is there any method of getting the DataRow to do this automatically?

  2. #2
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: Determining whether DataRow values have changed

    No there isn't (to my knowledge). Your approach is correct.
    If you set a DataRow field to the same value, the DataRow is changed.

  3. #3
    Join Date
    Feb 2001
    Location
    Sydney, Australia
    Posts
    1,909

    Re: Determining whether DataRow values have changed

    I believe thers's no that kind of functionality in DataRow or in DataTable.
    It would be better if you add validation (to check if the data was really changed or not) somewhere else. A good solution would be to add validation in UI.

    Quote Originally Posted by GazzaJ
    I have an application with a strongly typed Dataset which I populate and then transform the rows in the DataTable into objects used in my application. The application then updates the objects and I call code to update the appropriate DataRows before submitting the updates to the table.

    I originally wrote the method to update the DataRow to update each column in the row using the value in the object passed in. This however causes the RowState of the DataRow to change from Unchanged to Modified even if the value has not changed. Therefore I have logic to check the values in the DataRow with the value in the object and only update if there is a change, this logic incorporates checking for null values also.

    Is there any method of getting the DataRow to do this automatically?
    Best regards,
    Igor Sukhov

    www.sukhov.net

  4. #4
    Join Date
    Sep 2004
    Posts
    12

    Re: Determining whether DataRow values have changed

    This is how I do it:
    ------------------------------------------------------------------------------------------------
    Dim dataTableChanges As DataTable

    'Update the DELETED rows in the TBLVAARDIGHEDEN table first.
    dataTableChanges = nwDatasetInstance.tblVaardigheden.GetChanges(DataRowState.Deleted)
    If (Not (dataTableChanges) Is Nothing) Then
    Try
    mdaDataAdapterVaardigheden.Update(dataTableChanges)
    Catch eUpdate As System.Exception
    Throw eUpdate
    End Try
    End If
    ------------------------------------------------------------------------------------------------

    THEN,
    ------------------------------------------------------------------------------------------------
    ''update the ADDED and modified rows in the TBLVAARDIGHEDEN table.
    dataTableChanges = nwDatasetInstance.tblVaardigheden.GetChanges(DataRowState.Added Or DataRowState.Modified)
    If (Not (dataTableChanges) Is Nothing) Then
    Try
    mdaDataAdapterVaardigheden.Update(dataTableChanges)
    Catch eUpdate As System.Exception
    Throw eUpdate
    End Try
    End If




    You have to keep in mind, that if this works, that you then have to think
    out, what to do, if a record is changed or deleted simultaniously, by
    another user.
    You could do:
    Try
    mdaDataAdapterVaardigheden.Update(dataTableChanges)
    Catch dbcx As DBConcurrencyException
    SendMsgConcurrency("mdaDataAdapterVaardigheden")
    Catch eUpdate As System.Exception
    Throw eUpdate
    End Try


    Regards,

    Reinier

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured