C# sqlite 事务提交多个语句,提升插入速度

 

 

 

 

private SQLiteConnection connection;
private SQLiteCommand command;
private SQLiteTransaction transaction;
string sqConnectionString = "ZG.db";


public void ExcuteQuery()
{
connection = new SQLiteConnection("Data source = " + sqConnectionString);

connection.Open();

//建立数据库并连接

 

 

command = connection.CreateCommand();

transaction = connection.BeginTransaction();

//开启事务

 

////

command.CommandText = string.Format("INSERT INTO CINFO VALUES('0','1','2','3','4')");

command.ExecuteNonQuery();

/////插入语句,可循环插入

 

 


transaction.Commit();

//提交事务

 

 


command.Dispose();
connection.Dispose();

//结束连接


MessageBox.Show("插入完毕");


}

posted @ 2018-07-07 12:01  xfbx  阅读(440)  评论(0编辑  收藏  举报