我的更新代码:
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;
}
行数:18286
此版本需要5分钟
如何让它更快?
答案 0 :(得分:1)
您应该考虑使用哪个查询来提取ID并将其直接用于更新,因此您只需调用数据库一次:
"UPDATE customer set medaxil_status = '0' WHERE id in (select xxx xxx xxx)"
如果您想要更新所有行,只需删除where子句并调用语句一次。 如果您只有一个id列表,可能使用alwais来调用调用,IN子句将减少查询数量,并希望减少总体执行时间。
答案 1 :(得分:0)
答案 2 :(得分:0)
您是否尝试将循环包含在事务中?这加快了MS Access更新操作。
查看此示例here,其中显示了如何在C#中使用MS Access Transaction