启用事务操作,解决批量插入或更新sqlite,mssql等数据库耗时问_MySQL
程序员文章站
2024-01-28 18:40:40
...
bitsCN.com
private void btnImport_Click(object sender, EventArgs e) { string filePath = textBox1.Text; string importPwd = txtPwd.Text; if (string.IsNullOrEmpty(filePath) || string.IsNullOrEmpty(importPwd)) { MessageBox.Show("请先导入文件,填写操作密码后,再操作!"); } else { btnImport.Text = "正在导入..."; btnImport.Enabled = false; string[] allLines = File.ReadAllLines(filePath); using (SQLiteConnection con = new SQLiteConnection(connStr)) { con.Open(); DbTransaction trans = con.BeginTransaction();//开始事务 SQLiteCommand cmd = new SQLiteCommand(con); try { for (int n = 0; n
bitsCN.com