Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-02
4
Medium Priority
?
238 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
[X]
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
  • 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 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
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…

715 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