Copying large amounts of data into a SQL CE database

感情迁移 提交于 2019-12-08 01:26:37

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/884534/copying-large-amounts-of-data-into-a-sql-ce-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!