How to prevent RowChanging event when filling dataset

  • Thread starter Thread starter J
  • Start date Start date
J

J

I'm experimenting with strongly typed datasets, and when the .Fill method is
called, the RowChanging fires for each row. This causes a problem when the
existing data does not adhere to the rules outlined in the RowChanging
method. Is there an easy way to not have the RowChanging event occur when
the dataset is being filled?

Example code is

daTitleAuthor.Fill(dsAuthors1);

private void tblTitleAuthor_RowChanging(object sender,
dsAuthors.titleauthorRowChangeEvent e) {
if ( !e.Row.IsroyaltyperNull() ) {
if ( (e.Action == DataRowAction.Add || e.Action == DataRowAction.Change)
&& e.Row.royaltyper > 10) {
throw new Exception("Royalty cannot be greater than 10");
}
}
}
 
Hi,

What about unwiring the event handler before calling Fill and re-wiring it
after the Fill has completed?
 
That's what I ended up doing. It just seemed so crude and code intensive, I
was hoping there was a better way.

Dmitriy Lapshin said:
Hi,

What about unwiring the event handler before calling Fill and re-wiring it
after the Fill has completed?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

J said:
I'm experimenting with strongly typed datasets, and when the .Fill
method
is
called, the RowChanging fires for each row. This causes a problem when the
existing data does not adhere to the rules outlined in the RowChanging
method. Is there an easy way to not have the RowChanging event occur when
the dataset is being filled?

Example code is

daTitleAuthor.Fill(dsAuthors1);

private void tblTitleAuthor_RowChanging(object sender,
dsAuthors.titleauthorRowChangeEvent e) {
if ( !e.Row.IsroyaltyperNull() ) {
if ( (e.Action == DataRowAction.Add || e.Action == DataRowAction.Change)
&& e.Row.royaltyper > 10) {
throw new Exception("Royalty cannot be greater than 10");
}
}
}
 
Back
Top