Solved

How to determine if data on a form has been modified using Visual Basic

Posted on 2009-04-02
4
231 Views
Last Modified: 2013-11-26
I am new to Visual Basic and have learned mainly from Trial and Error.  I definitely don't do things the way they are supposed (at least that is what I think.)  Here is my problem.  I have a windows form that displays a datagrid of employees.  When the user double clicks on an employee it opens another form where the data can be modified.  The way I accomplish this is to have a check for an employee id  on the form that gets set from the first form (employeeid).  Using the employeeid, I use the following code to load the record onto the form (see EmployeeLoad Event code).  Now what I want to do is to see if any changes have been made to the record before allowing the form to be closed (see CancelAddButton_Click code).

I never get the Prompt to Save data message.  When debugging, EmployeeDrow.RowState always says Unchanged.  What am I doing wrong?

EmployeeLoad Event
 

Me.EmployeesTableAdapter.FillByEmployeeWithEmployeeID(pfmsDataSet1.Employees, EmployeeIDText.Text)

If pfmsDataSet1.Employees.Count = 1 Then

   EmployeeDrow = pfmsDataSet1.Employees.Rows(0)  ' EmployeeDrow is a global variable

Else

   MsgBox("More than 1 employee found")

End If
 

===========================================================================

CancelAddButton_Click code
 

If EmployeeDrow.RowState = DataRowState.Modified Then

   MsgBox("Prompt to save data")

Else

  Me.Close()

End If

Open in new window

0
Comment
Question by:dyarosh
  • 2
  • 2
4 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24049087
0
 

Author Comment

by:dyarosh
ID: 24049522
Modified CancelAddButton_Click to the following:
If pfmsDataSet1.HasChanges() Then
   MsgBox("prompt to save')
End If
Me.Close
I still don't get the prompt.
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 24049556
Do you call pfmsDataSet1.AcceptChanges() anywhere? This would cause all modified rows to change to Unchanged.

Wayne
0
 

Author Closing Comment

by:dyarosh
ID: 31565755
pfmsDataSet1.AcceptChanges() did not work.  Since the data is bound on the form I used EmployeesBindingSource.EndEdit() and now I get prompted when the data is changed.  Thanks for your help.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now