【发布时间】:2012-06-19 07:00:17
【问题描述】:
我的更新代码:
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 分钟
如何让它更快?
【问题讨论】:
-
如何提取 id 进行操作?
-
你的意思是你必须用 medaxil_status = '0' 更新所有行?
-
您可以尝试使用存储过程。它会工作得更快一些。在此之前,您可以尝试使用一些实际值执行单个查询“UPDATE customer set medaxil_status = '0' WHERE id =” + this.MedaxilGridView1.Rows[i].Cells["id"].Value;" 并检查多长时间它需要。这将帮助您了解哪个部分花费了太多时间。循环或 sql 本身。
-
您还应该查看参数化查询,以确保您的代码不会受到 sql-injection 的影响。
标签: c# sql database performance ms-access