将大量数据复制到SQL CE数据库中

时间:2021-08-31 15:59:36

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.

如果我在内存中有大量数据,那么将它复制到SQL CE表的最佳方法是什么?当前的技术堆栈是C#,ADO.net和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?

我最初的想法是为每行数据执行一个INSERT语句,但这非常耗时。有没有更简单的方法?

2 个解决方案

#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

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

我不确定您的SQL CE版本是否支持它(尽管从MSDN页面上可以看出它似乎在3.5 SP1中支持)。 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.

Steve Lasker有一个很好的代码示例使用不同的方法演示这个,但最好的方法(到目前为止)是SqlCeResultSet。

Here is a blog post from Steve with some good powerpoints on this subject.

这是史蒂夫的博客文章,在这个主题上有一些很好的权力。

#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

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

我不确定您的SQL CE版本是否支持它(尽管从MSDN页面上可以看出它似乎在3.5 SP1中支持)。 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.

Steve Lasker有一个很好的代码示例使用不同的方法演示这个,但最好的方法(到目前为止)是SqlCeResultSet。

Here is a blog post from Steve with some good powerpoints on this subject.

这是史蒂夫的博客文章,在这个主题上有一些很好的权力。