DataTable update cells slow

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using a DataTable in my application. I am able to load rows into the DataTable quickly. What's puzzling me, however, is that when I update a set of cells in the DataTable, the update is really slow

my update code amounts to

dataTable.BeginLoadData()
dataSet.EnforceConstraints = false
tr

for(iRowHandle = 0; iRowHandle < iLimit; iRowHandle++

dataTable.Rows[iRowHandle][iColumn] = szNewValue


finall

dataSet.EnforceRestraints = true
dataTable.EndLoadData()


when I run the above, the update rate is approximately 200 cells/second. This is pathethic. Databases update faster than that. What's weird to me is that I can add rows to the table at about 4000 records/second (each record in this case is 9 columns). So something doesn't add up. Why does the "add-rows" go quickly, but a simple non-key column update is really slow

I must be doing something wrong. But I can't figure out what. It is almost as if each cell update fires a whole bunch of events. But I thought call BegingLoadData, and EnforceRestraints = false were supposed to prevent these events from firing

Can anyone help

Also, does anyone know how to track DataTable events from the debugger

Thanks
 
I figured out my issue.

I needed to call the DataRow.BeginEdit() prior to setting each value.

Then in my finally clause, I needed to call the dataTable.AcceptChanges.

This made the update go over 10000 rows/sec
 
Back
Top