HasChanges On New Record = Not Modified!!!

ChubbyArse

Member
Joined
Jun 10, 2003
Messages
19
Hi All,

I have a dataset in a form with bound controls
I fill the dataset from an adapter and am implementing the commandbuilder
too.

I call

Me.BindingContext(dsCustomers, strTableName).EndCurrentEdit()
Me.BindingContext(dsCustomers, strTableName).AddNew()

to goto a new record (strTable is a variable containing the Table name)
and then I update some of the fields. Then I call from a button:

Me.BindingContext(dsCustomers, strTableName).EndCurrentEdit()
bolNewRecord = dsCustomers.HasChanges(DataRowState.Added)

bolNewRecord evaluates to true, but the lines evaluate as shown:
dsCustomers.HasChanges(DataRowState.Modified) = False
dsCustomers.HasChanges(DataRowState.Unchanged) = True

Why does it say that my new record is not modifed??

Thanks

Alex
 
I think it would be easier to evaluate what you are doing if you copy the actual block of code and paste it here. If you are confident of you connection, dataadapter, commandbuilder and dataset objects, leave that part behind. Include the portion that begins with: Me.BindingContext(dsCustomers, strTableName).EndCurrentEdit() however, Im curious to see how that fits in the picture...through the check on the .HasChanges

Jon
 
when you call EndCurrentEdit all HasChanges states in your table
are set to not Modified so, you can call EndCurrentEdit for example after you update your database..
 
The problem is checking the state of a new record which has been modified.
The HasChanges(DataRowState.Added) is true, but the HasChanges(DataRowState.Modifed) is False and HasChanges(DataRowState.Unchanged) is True.
This would lead you to believe the new record has not been changed.
 
Not suprisingly, if the value of any column of a DataRow is changed after AcceptChanges is called (usually either by the Fill or Update methods of the DataAdapter), its RowState is set to Modified. If new DataRows are added to the DataSet by using the Add method of the DataSets Row collection, their RowState will be Added. The new rows will maintain the status of Added even if their contents are changed before the next call to AcceptChanges.

Jon
 
Originally posted by sizer
when you call EndCurrentEdit all HasChanges states in your table
are set to not Modified so, you can call EndCurrentEdit for example after you update your database..


Actually BeginEdit suspends the Column and Row change events until either EndEdit or CancelEdit are called. During the editing process, assignmnets are made to the Proposed version of the DataRow instead of to the Current version. This is the only time the Proposed version exists. If the edit is completed by calling EndEdit, the Proposed column values are copied to the Current version and the Proposed version of the DataRow is removed. This is particularly handy when it is necessary to temporarily suspend validation of data until a series of edits have been performed either for performance reasons or because rows will temporarily be in violation of business or integrity constraints.


Jon
 
The problem is that the HasChanges(DataRowState.Modifed) method does not report correctly for a new record.
The HasChanges(DataRowState.Added) correctly reports that a new record has been added, but I can in no way see how I can test that a new record has been modifed, before it is saved.
 
It is reporting correctly, the new record will not have a RowState of modified, only Added. Why do you need to know if an added row has changes verses when it was originally added to the collection? Can you explain what you are trying to achieve and show us the code?


Jon
 
What I am trying to achieve is to be able have a save method, which will check the record, and prompt the user as to whether or not they want to save the record.

With an exsiting record this is fine, as I just check HasChanges(DataRowState.Modifed) and this reports back True.

When I check the same on a new record which has had fields changed, the HasChanges(DataRowState.Modifed) reports false.

However, regardless of whether Ive edited my new record, or just left it alone, HasChanges(DataRowState.Added) reports true and HasChanges(DataRowState.Modifed) reports false. Therefore

I cannot disctingush between a new record which has not been edited (the user clicks new then save immediately), and a new recod which has been modified (the user has typed into a field).
I dont want to ask the user if they want to save, when there is nothing to save!!!!
 
My Code:

(NewButton)...
cm.EndCurrentEdit()
cm.AddNew()

(User modifies fields)

(SaveButton)...
cm.EndCurrentEdit()
bolNewRecord = dsFormData.HasChanges(DataRowState.Added)

Check if the record has changed, if not return true
If Not dsFormData.HasChanges(DataRowState.Modified) Then
Return True
Else
Msgbox("Do you wish to save........")
End If

etc.........
 
A new record will never have a state of modified it will stay as added until you call AcceptChanges(), if i understood correctly , You can simply select the rows which are added by the user and check if they contain data and they do prompt the user if he wants to save if they dont then ignore the user.....
 
Hello,

You can not check if the user has entered something in the new record or not by this HasChanges(DataRowState.Modifed).

Instead you should check the Value of the Primary key field and if find it blank you can just say CancelCurrentEdit.

Viast

Originally posted by ChubbyArse
What I am trying to achieve is to be able have a save method, which will check the record, and prompt the user as to whether or not they want to save the record.

With an exsiting record this is fine, as I just check HasChanges(DataRowState.Modifed) and this reports back True.

When I check the same on a new record which has had fields changed, the HasChanges(DataRowState.Modifed) reports false.

However, regardless of whether Ive edited my new record, or just left it alone, HasChanges(DataRowState.Added) reports true and HasChanges(DataRowState.Modifed) reports false. Therefore

I cannot disctingush between a new record which has not been edited (the user clicks new then save immediately), and a new recod which has been modified (the user has typed into a field).
I dont want to ask the user if they want to save, when there is nothing to save!!!!
 
Back
Top