Copying large amounts of data into a SQL CE database
-
23-08-2019 - |
Question
If I have a large amount of data in memory, what is the best way to copy it into a SQL CE table? The current technology stack is C#, ADO.net, and SQL CE.
My initial idea was to do one INSERT statement for each row of data, but this is time-consuming. Is there an easier way?
Solution
The first thing that popped into my head was to do a sync/merge with a desktop or server database, though that doesn't sound like it really fits your needs. So here is my second thought:
BULK INSERT table_name FROM data_file
I am not sure if it is supported in your version of SQL CE (though it appears to be supported in 3.5 SP1 from what I can tell on the MSDN pages). http://msdn.microsoft.com/en-us/library/ms188365.aspx
You could also disable any indexes on the table while inserting the data to speed things up, then enable/rebuild the index once you are done inserting.
OTHER TIPS
Steve Lasker has a great code sample demoing this with different methods, but the best method (by far) is SqlCeResultSet.
Here is a blog post from Steve with some good powerpoints on this subject.