Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2009-04-02
4
234 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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