Solved

c# Check for Pending Updates

Posted on 2014-12-16
6
176 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 32

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

22 Experts available now in Live!

Get 1:1 Help Now