Dataset HasChanged Property

I'm Making a database program I've noticed that the property HasChanged intented to track wether the dataset has changed does not update it's value to True in case of the user has edited the data on the screen till you move to another record

can I know if the user changed the data before the user leaves the current edited record to another

the purpos of this is to alert the user to save data before he mopves to another record or close the form

in the simplest way It colud be done

Thank You all



Answer this question

Dataset HasChanged Property

  • Brad W

    The code I posted does not actually update the row--it just displays a message box if it has changed. To update, you would call datarow.acceptchanges method.
  • K C

    @ MacMatt_98

    I understand That But I want to konw if the record has been changed before I move to next record

    suppose the user ended the program without saving if he didn't move to the next record how I can alert him before acytally ending the program


  • brad oyler

    The changes you are making will be accepted into the dataset when you move to a different record after making some chnages to the data.

    However you can call the AcceptChanges method

    http://msdn2.microsoft.com/en-US/library/system.data.dataset.acceptchanges.aspx

    Which commits all the changes made to this dataset/datarow since it was loaded or since the last time AcceptChanges was called.

    This acceptchanges could be called on any event such as moving to a different control on a databound details form - so you changes are reflected immediately in the dataset upon moving to a different control for the same record.

    Hope that helps.


  • coesurf

    Not a problem.

    I thought you might not want to accept changes on the dataset because it changes the RowState of all the rows to Unchanged, depending on how your updating your database you may want to use the row state information to do the updating.


  • RWatson

    Thank you I'll try That
  • narend

    No that does not solve the problem

    it has the same problem of the property HasChanges

    problem still unsolved


  • DusanMihajlovic

    Thnak you Lifer that really solved it

    I don't know how this property slipped my mind


  • Graham King

    Thank you but

    Still the same problem property does not updated till you move to the next record

    no solution yet


  • Kevin8264

    If you really want to see if the row has changed, you can reference the rowstate property. Example:

    Dim dr As DataRow = TestDataTable.Rows(IndexOfCurrentRow)

    If dr.RowState = DataRowState.Modified Then

    MsgBox("Save changes ")

    End If


  • mario l gutierrez

    Have you tried ending the edit on the grid and the dataset

    Private Sub EndCurrentEdit()

    '

    ' Attempt to end editing on the DataGrid

    '

    If _Dedup.DedupDT.Rows.Count > 0 Then

    With DedupGrid

    .EndEdit(gridColumn:=.TableStyles(0).GridColumnStyles.Item(.CurrentCell.ColumnNumber), _

    rowNumber:=.CurrentCell.RowNumber, _

    shouldAbort:=False)

    CType(Me.BindingContext(MyDataSet, "DataMember"), CurrencyManager).EndCurrentEdit()

    End With

    End If

    End Sub


  • Dataset HasChanged Property