S
Sorin Dolha
Hello,
This is probably a known issue or a FAQ. However, I could not find a
straight answer to the question, or a nice workaround, so I appologize if
this was answered before (in that case, I would appreciate if someone will
provide a link to a previous related thread or article).
I have a DataSet containing several tables. I am listening to
DataTable.RowChanged event to listen to row additions and changes, and to
DataTable.RowDeleted event of those tables to listen to row deletions. Both
events are triggering the same method that is using DataSet.GetChanges()
method to get all the changes made to the DataSet. For row changes and
deletions, everything is correct (the changes/deletions are returned by the
GetChanges() method as appropriate), but for row additions, the GetChanges()
returns null (or a dataset that does not contain the newly added row).
Therefore, believe that the RowChanged event is triggered just before adding
the row to the DataSet, and not after. However, there is no RowAdded event
or something similar that would allow me to GetChanges() immediately after a
row was added to the collection.
Is this a bug, or is it designed this way? If the latter, can you please
provide reasons why this design was chosen? Any known workarounds?
Workarounds that I have thought of:
1. Not thread-safe:
Within the RowChanged event handler, when DataRowAction is equal to Add,
create and start a new thread using a method that actually get changes()
later (when hopefully the DataSet will have been added the new row to the
collection);
2. Thread-safe:
Within the RowChanged event handler, when DataRowAction is equal to Add, get
DataSet changes by calling code like this:
DataSet ds = dataSet.GetChanges();
if (ds==null) ds = dataSet.Clone();
ds.EnforceConstraints = false;
ds.Tables[e.Row.Table.TableName].Rows.Add(e.Row.ItemArray);
//use ds as the changes
Both workarounds are not nice, in my opinion, therefore I am currently
looking for a better solution. Is ADO .NET 2.0 coming with an changes in the
way DataTable events are provided and raised?
Thank you,
Sorin Dolha
MCAD, MCSD .NET
This is probably a known issue or a FAQ. However, I could not find a
straight answer to the question, or a nice workaround, so I appologize if
this was answered before (in that case, I would appreciate if someone will
provide a link to a previous related thread or article).
I have a DataSet containing several tables. I am listening to
DataTable.RowChanged event to listen to row additions and changes, and to
DataTable.RowDeleted event of those tables to listen to row deletions. Both
events are triggering the same method that is using DataSet.GetChanges()
method to get all the changes made to the DataSet. For row changes and
deletions, everything is correct (the changes/deletions are returned by the
GetChanges() method as appropriate), but for row additions, the GetChanges()
returns null (or a dataset that does not contain the newly added row).
Therefore, believe that the RowChanged event is triggered just before adding
the row to the DataSet, and not after. However, there is no RowAdded event
or something similar that would allow me to GetChanges() immediately after a
row was added to the collection.
Is this a bug, or is it designed this way? If the latter, can you please
provide reasons why this design was chosen? Any known workarounds?
Workarounds that I have thought of:
1. Not thread-safe:
Within the RowChanged event handler, when DataRowAction is equal to Add,
create and start a new thread using a method that actually get changes()
later (when hopefully the DataSet will have been added the new row to the
collection);
2. Thread-safe:
Within the RowChanged event handler, when DataRowAction is equal to Add, get
DataSet changes by calling code like this:
DataSet ds = dataSet.GetChanges();
if (ds==null) ds = dataSet.Clone();
ds.EnforceConstraints = false;
ds.Tables[e.Row.Table.TableName].Rows.Add(e.Row.ItemArray);
//use ds as the changes
Both workarounds are not nice, in my opinion, therefore I am currently
looking for a better solution. Is ADO .NET 2.0 coming with an changes in the
way DataTable events are provided and raised?
Thank you,
Sorin Dolha
MCAD, MCSD .NET