Solved

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

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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