Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Save data On Exit (prompt)

Avatar of John (Yiannis) Toutountzoglou
John (Yiannis) ToutountzoglouFlag for Greece asked on
Visual Basic.NET
16 Comments1 Solution380 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...