Solved

c# Check for Pending Updates

Posted on 2014-12-16
6
180 Views
Last Modified: 2014-12-16
How do I recognize if a record has updates pending? I want to determine this before allowing the user to move to another record & request that they commit the changes.

I have a c# 4.5 windows form with a Dataset, BindingNavigator, BindingSource, & TableAdapter all being used to bind the data to the form objects. Record Navigation is provided by click events on the BindingNavigator menu.
0
Comment
Question by:Lensolo
  • 5
6 Comments
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 40502851
If you are bound to the DataRow, then you can use the DataRow.RowState property to determine the row state.

http://msdn.microsoft.com/en-us/library/system.data.datarow.rowstate(v=vs.110).aspx

To that end, you can bind to the RowChanged event on the DataTable object when you are Binding so that you can detect row changes and act appropriately.

http://msdn.microsoft.com/en-us/library/w9y9a401(v=vs.110).aspx

-saige-
0
 

Author Comment

by:Lensolo
ID: 40502933
What I am having a hard time doing is capturing the DataTable event. On the form load, I had this entry:

 
private void TestForm_Load(object sender, EventArgs e)
{
this.TableAdapter.Fill(this.DataSet.TableName);
}

Open in new window

I changed this to the following:
private void TestForm_Load(object sender, EventArgs e)
{
this.TableAdapter.Fill(this.DataSet.TableName);
this.DataSet.TableName.RowChanging += new DataRowChangeEventHandler(Row_Changing);
}

private static void Row_Changing(object sender, DataRowChangeEventArgs e)
 {
     MessageBox.Show("Row_Changing Event kicked off");
 }

Open in new window


I have not done this before, but it seems like it should work, however I never get a message when navigating between the rows.
0
 

Author Comment

by:Lensolo
ID: 40502980
Whoops Sorry. The row changing event kicks off when I try to leave a row that has a change on it. I thought it meant just when you leave a row.

MSDN Description of RowChanging: "Occurs when a change has been submitted for a DataColumn value or the RowState of a DataRow in the DataTable."

So far this seems to work like a champ on identifying when a change occurred. I need to play around with it some, but this may work.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Lensolo
ID: 40502989
This causes other issues at present. Let me play around with the suggested routine & see if I can get this to work.
0
 

Author Comment

by:Lensolo
ID: 40502995
I see you suggested RowChanged. I'll try to use this instead.
0
 

Author Comment

by:Lensolo
ID: 40503086
This works. It gave me a surprise in that it is called for every row in the dataset during the Dataset.AcceptChanges(), but it makes sense. You just don't want to use this to call a save routine. Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Image(7) 1 53
fomat Json objects 6 28
Memory Usage 2 50
SQL Exceptions 3 39
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

21 Experts available now in Live!

Get 1:1 Help Now