Click to See Complete Forum and Search --> : Determining whether DataRow values have changed


GazzaJ
October 20th, 2005, 10:55 AM
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?

jhammer
October 23rd, 2005, 06:45 AM
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.

Igor Soukhov
October 23rd, 2005, 07:01 PM
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.

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?

ADOration39
November 4th, 2005, 03:31 PM
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