Solved

c# Check for Pending Updates

Posted on 2014-12-16
6
196 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
[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
  • 5
6 Comments
 
LVL 34

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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
linq, c# 8 50
linq .concat equivalent with expression syntax 4 41
c# ftp code 3 56
Example code 13 42
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

739 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