Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以C#最佳方式更新MS Access数据库_C#_Sql_Database_Performance_Ms Access - Fatal编程技术网

以C#最佳方式更新MS Access数据库

以C#最佳方式更新MS Access数据库,c#,sql,database,performance,ms-access,C#,Sql,Database,Performance,Ms Access,我的更新代码: for (int i = this.MedaxilGridView1.CurrentCell.RowIndex; i < this.MedaxilGridView1.RowCount; i++) { // KartsifarishiGridView-dən id götürüb ona uyğun sorğumuzu yazırıq. sqlSorgu = "UPDATE customer set medaxil_status = '0' WHERE

我的更新代码:

 for (int i = this.MedaxilGridView1.CurrentCell.RowIndex; i < this.MedaxilGridView1.RowCount; i++)
 {
     // KartsifarishiGridView-dən id götürüb ona uyğun sorğumuzu yazırıq.
     sqlSorgu = "UPDATE customer set medaxil_status = '0' WHERE id = " + 
                 this.MedaxilGridView1.Rows[i].Cells["id"].Value;
     //Sorğunu icra edirk.
     Program.esas.sqlSorguCommand.CommandText = sqlSorgu;
     Program.esas.sqlSorguCommand.Connection = Program.esas.bazayaQosul;
     Program.esas.sqlSorguCommand.ExecuteNonQuery();
     MedaxilGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Empty;

 }
for(int i=this.MedaxilGridView1.CurrentCell.RowIndex;i
行数:18286

这个版本需要5分钟


如何使其更快?

您可以使用
BeginExecutenQuery
为此,通过打开一个连接并批量执行所有查询,将节省连接启动开销

可以找到MSDN的完整示例


此外,我建议您开始使用

您应该考虑使用哪个查询来提取id并将其直接用于更新,因此您可以调用数据库一次:

"UPDATE customer set medaxil_status = '0' WHERE id in (select xxx xxx xxx)"
如果要更新所有行,只需删除where子句,并调用语句一次即可。
如果您只有一个id列表,那么使用alwais IN子句对调用进行分块可能会减少queryes的数量,并有望减少总体执行时间。

您是否尝试将循环包含在事务中?这将加快MS Access更新操作的速度


看看这个示例,它展示了如何在C#

中使用MS Access事务。如何提取要使用的id?您的意思是必须使用medaxil#u status='0'更新所有行?您可以尝试使用存储过程。它会工作得快一点。在此之前,您可以尝试执行单个查询“UPDATE customer set medaxil_status='0',其中id=“+this.MedaxilGridView1.Rows[i].Cells[“id”].Value;“使用一些实际值并检查它需要多长时间。这将帮助您意识到哪一部分花费的时间太长。是循环还是sql本身。您还应该研究参数化查询,以确保您的代码不能被sql注入使用。@Ozgur Dogus Abi bir misal koy bakimAll interlinear not.Selected row-last”row@FelicePollano是的,你可以n、 我只想0