troubleshooting Question

Save data On Exit (prompt)

Avatar of John (Yiannis) Toutountzoglou
John (Yiannis) ToutountzoglouFlag for Greece asked on
Visual Basic.NET
16 Comments2 Solutions380 ViewsLast Modified:
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...
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros