none
Vb.net Haschanges Method

    Question

  • Private Sub frm_StoreMaster_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    If MyDataSet.HasChanges() Then
                Try
                    If MsgBox("Save Changes?", MsgBoxStyle.OkCancel, Me.Text) = MsgBoxResult.Ok Then
                        Me.StoretMasterBindingSource.EndEdit()
                        Me.TableAdapterManager.UpdateAll(Me.MyDataSet)
                        Me.MyDataSet.AcceptChanges()
                    Else
                        StoreMasterBindingSource.CancelEdit()
                        MyDataSet.RejectChanges()
                        Me.Refresh()
                    End If
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            End If
    hye, i try to run the code, then i change the data and close the form..but why the msgbox that prompt to save record does not appear?
    Monday, June 27, 2011 7:37 AM

All replies

  • In my idea are you combining old style code with new style code.

     If MessageBox.Show("Save Changes?") = DialogResult.Ok Then


    Success
    Cor
    Monday, June 27, 2011 8:23 AM
  • Did you try to debug and check if the MsgBox line is executed at all?

    How are you changing the data in your dataset? Is it being updated by the user in a DataGridView ? Are you sure you are not calling the AcceptChanges method on the Dataset or its DataTable/Rows?


    Please mark this as answer or vote as helpful if it solved your problem
    Monday, June 27, 2011 8:33 AM
  • @GregHenry,

    I was going also in that fall, the messagebox is a seperated instruction which has in fact nothing to do with all the others

    So I could stuff my long message about the haschanges, acceptchanges and rejectchanges

    :-)


    Success
    Cor
    Monday, June 27, 2011 8:35 AM
  • Hi Greg,

    i already debug the code. 

    the code is actually i took from  StoreMasterBindingNavigatorSaveItem_Click which is as below, and it's work..

     

    Private Sub StoreMasterBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AssetMasterBindingNavigatorSaveItem.Click

             If MsgBox("Save Changes?", MsgBoxStyle.OkCancel, Me.Text) = MsgBoxResult.Ok Then

                Me.AssetMasterBindingSource.EndEdit()

                Me.TableAdapterManager.UpdateAll(Me.MyDataSet)

                Me.MyDataSet.AcceptChanges()

            Else

                StoreMasterBindingSource.CancelEdit()

                MyDataSet.RejectChanges()

                Me.Refresh()

            End If

     

     

    then i just add this method, MyDataSet.HasChanges() in order to check if there is changes..unfortunately it does not work.

    i am not using datagridview. i am using several textbox,calender and others.but i think i doesn't matter since im just checking from the dataset.

     

    p/s:how to check if the msgbox line is executed or not? 

    Monday, June 27, 2011 9:48 AM
  • Duh,

    I did not see that line beneath the Method.

    Me.StoretMasterBindingSource.EndEdit()
    If MyDataSet.HasChanges() Then
          Try
            If MsgBox("Save Changes?", MsgBoxStyle.OkCancel, Me.Text) = MsgBoxResult.Ok Then
            
              Me.TableAdapterManager.UpdateAll(Me.MyDataSet)
              Me.MyDataSet.AcceptChanges()
            Else
    


    This pushes not yet acknowledged data because of a row change inside the dataset and creates the changes.

     


    Success
    Cor
    Monday, June 27, 2011 2:13 PM