|
|
Control datatable and row events programatically |
|
Author |
Message |
bpeikes

|
Posted: .NET Framework Data Access and Storage, Control datatable and row events programatically |
Top |
I want to turn off events on several tables in a datset,
which I know I can do using BeginLoadData. The problem is that I want
to raise update events on specific rows after I call EndLoadData. Specific example: I have a datatable Data, and a datatable Summary. I update rows in the Data table but do not want events raised regarding the changes in Data until I've also updated Summary.
Basically I need transactions, but applied to updates of a dataset. Any ideas I suppose I could lock the individual rows, but then I have to make sure to attempt a lock before accessing a row every time.
.NET Development3
|
|
|
|
 |
cverdon

|
Posted: .NET Framework Data Access and Storage, Control datatable and row events programatically |
Top |
Hi,
One way to do this is to call SetModified for every row that you need to generate the RowUpdated event:
foreach ( DataRow dr in tb.Rows ) { if ( dr.HasErrors ) { //row matches
some arbitrary criteria //raise
modification event dr.SetModified(); } }
If that's not what you need please provide a specific example.
Charles
|
|
|
|
 |
bpeikes

|
Posted: .NET Framework Data Access and Storage, Control datatable and row events programatically |
Top |
The problem is that I want all of the "changes" committed to the dataset before raising the event. Example: Table1 in the dataset holds a list of people, their ages and genders. Table2 holds summary information about the people in table1. Let's say it's average age for each gender.
I update a person in table1. I want to also update the averages in table2 and then have an event raised for the person row and for the average row(s). I need to make sure that the table has the updated information when the event is called.
For instance, lets say I have code which looks for changes in the people records, and then displays the average age for their age group. If I fire an event as soon as the people row changes, they code won't have access to the new average info. If I change the average first and fire an event, the people data won't match the avergages.
|
|
|
|
 |
cverdon

|
Posted: .NET Framework Data Access and Storage, Control datatable and row events programatically |
Top |
To raise the events there are not taht many options, either you call SetModified and then cancel the 'modification' after, or you create your own events.
Charles
|
|
|
|
 |
JThiloR

|
Posted: .NET Framework Data Access and Storage, Control datatable and row events programatically |
Top |
May be, I would try to use triggers (on the database side) or a seperate view or UDF which calculates the column in the database.
|
|
|
|
 |
|
|