What's the sense of BeginLoadData / EndLoadData (System.Data.DataTable)

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

Guest

Hello NG!

MSDN sais:

To ensure best performance for ReadXml, on a large file, call the
DataTable.BeginLoadData method for each table in the DataSet, then call
ReadXml. Finally, call DataTable.EndLoadData for each table in the DataSet
as shown in the following example.

For Each t In ds.Tables
t.BeginLoadData()
Next

ds.ReadXml("file.xml")

For Each t in ds.Tables
t.EndLoadData()
Next


I've added this code to my (CompactFramework) application to get better
performance and "ReadXML" really speeds up. Jeahh...
BUT when calling "EndLoadData" it seems like the tables are doing all the
things afterwards, they haven't done while "ReadXML"... So to me it's
totally sensless...

Thanks, D.Barisch
 
It's quite not totally senseless.

EndLoadData will validate all the constraints, just once after all the data
is loaded. Whereas not calling that would do that row by row.

You can run a quick comparison test to check the difference. The same
technique is often applied in databases (disable all constraints before a
bulkload of data) to get better load times.


- Sahil Malik
http://codebetter.com/blogs/sahil.malik/
 
Back
Top