How do you avoid that events are thrown when updating a datatable?

I have been searching for a while on the internet for a way to update a DataTable and turning of the event notification while doing it. My research still have not gotten me an answer. The following code should work I thought, but it does not:
DataTable tb = new DataTable();
tb.Columns.Add(new DataColumn("id", System.Type.GetType("System.Decimal")));
tb.BeginLoadData();
tb.LoadDataRow(new Object[] {1}, false); // This row still throws the event.
tb.EndLoadData();
I have initiated the event handler accordingly:
tb.RowChanged += new DataRowChangeEventHandler(tb_RowChanged);
and in the method tb_RowChanged I still get the events. MSDN says the following on the BeginLoadData method:
"Turns offnotification, index maintenance, and constraints while loading data."

Is this a bugSad and in such case, is there a nice way to solv this problem? I.e. making the DataTable not throwing events.Smile

[1076 byte] By [SoftwareAndWhy] at [2008-1-21]
# 1

Hi Tobias,

A simple, yet powerful solution to your problem has been suggested by Miha Markic, MVP C#, here:

http://www.msusenet.com/archive/index.php/t-2806709.html

Regards,

George

GeorgeBolsch at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2
SoftwareAndWhy wrote:
I have been searching for a while on the internet for a way to update a DataTable and turning of the event notification while doing it. My research still have not gotten me an answer. The following code should work I thought, but it does not:

DataTable tb = new DataTable();
tb.Columns.Add(new DataColumn("id", System.Type.GetType("System.Decimal")));

tb.BeginLoadData();
tb.LoadDataRow(new Object[] {1}, false); // This row still throws the event.
tb.EndLoadData();

I have initiated the event handler accordingly:
tb.RowChanged += new DataRowChangeEventHandler(tb_RowChanged);
and in the method tb_RowChanged I still get the events. MSDN says the following on the BeginLoadData method:

"Turns off notification, index maintenance, and constraints while loading data."
Is this a bug Sad and in such case, is there a nice way to solv this problem? I.e. making the DataTable not throwing events. Smile

SoftwareAndWhy,

It would seem to me that this is a bug (I verified the documentation, and agree).

I would recommend filing a bug at:

http://lab.msdn.microsoft.com/productfeedback/Default.aspx

It will be placed in the bug system at MS, and they will be notified of it.

Hope this helps.

- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

casperOne at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified