Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-04-02
4
Medium Priority
?
240 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 48

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 48

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

824 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