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

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
 
S

Sahil Malik

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top