Avatar of John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou
Flag for Greece

asked on 

Save data On Exit (prompt)

I use a function For saving Data to dataset As the following code ...
I use Has Changes Method and saved data correctlly
The usual qusetion ...Prompt for save on exit .
The Boolean is Save...
The problem is when the form opens in addnew mode and you press Exit and no changes has made the message appears again...

Private Function Save() As Boolean
        Dim Saved As Boolean = False
        If MyDataSet.HasChanges Then
            Try
                Dim myUpdates() As DataRow = MyDataSet.Personnel.Select("", "", DataViewRowState.Added Or DataViewRowState.ModifiedCurrent)
                Me.MyTableAdapter.Update(MyUpdates)
              Saved = True
                           Catch ex As Exception
                'MsgBox(ex.Message)
                
           End Try
        End If
        Return Saved
           End Function
 
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'button 3 =SAVE BUTTON
        Me.Validate()
        Me.MyBindingSource.EndEdit()
        If Me.Save() Then
messagebox.show(".......")
 
       end if 
Private Sub Exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Exit.Click
If Not Me.Save Then
            Select Case MessageBox.Show("Exit Without SAVE...Do You Want to Save Data?", "Data Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
 
                Case Windows.Forms.DialogResult.Yes
                    Me.Validate()
                    Me.MyBindingSource.EndEdit()
                    Me.Save()
                    Me.hide
 
 Case Windows.Forms.DialogResult.No
                    '-- do nothing
                                       Me.Hide()
End Select
        Else
            Me.Hide()
        End If
 
The problem is when the form opens in addnew mode and you press Exit and no changes has made the message appears again...

Open in new window

Visual Basic.NET

Avatar of undefined
Last Comment
John (Yiannis) Toutountzoglou

8/22/2022 - Mon