您好,欢迎访问一九零五行业门户网

启用事务操作,解决批量插入或更新sqlite,mssql等数据库耗时问_MySQL

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 < alllines.length; n++) { cmd.commandtext = insert into imei(imei) values(@imei); cmd.parameters.add(new sqliteparameter(@imei, dbtype.string)); cmd.parameters[@imei].value = alllines[n]; cmd.executenonquery(); } trans.commit();//提交事务 messagebox.show(文件导入成功!); } catch (exception ex) { trans.rollback(); messagebox.show(文件导入错误,请检查是否重复导入或其它原因!); } finally { btnimport.text = 导 入; btnimport.enabled = true; } } } }
bitscn.com
其它类似信息

推荐信息