我从这个问题开始How to Insert and Update in SQLite using SQLite-net
然而,它需要的时间比它应该长很多。这在答案/评论中注明:
谢谢,看起来它正在工作......但非常非常慢... 32,000条记录复制到数据库需要3-4分钟。它只有3列......奇怪为什么这么慢? - Tommix 2011年11月27日12:30
尝试在事务中执行更新;如果没有显式事务,SQLite会为每个插入隐式创建一个,这对于大量插入来说非常慢。此外,32k记录相当大,也许您应该尝试以较小的批次进行。 - Thomas Levesque 2011年11月27日17:38
以下是我用来从MS SQL创建的数据表更新本地SQLite DB的代码。如何在交易中执行此操作?
SQLiteDataAdapter dataUpdate = new SQLiteDataAdapter("SELECT * FROM ItemMaster", sqLiteconnection);
var cmdBuilder = new SQLiteCommandBuilder(dataUpdate);
dataUpdate.Update(dataInsertStagingTable);
mConnect.Close();
sqLiteconnection.Close();
答案 0 :(得分:0)
看起来我想通了,发现这不是我的主要问题。主要问题是参数化insert语句。我还把它包装在交易中。这个问题可以在回答时结束。
using (SQLiteTransaction tran = sqLiteconnection.BeginTransaction())
{
<for loop inserts here>
tran.Commit();
}
sqLiteconnection.Close();