c#每循环100次提交一次数据,最后一次不足100次提交一次

            StringBuilder sb=new StringBuilder();
            string strId=dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["id"].Value.ToString();
            int iCnt = 0;//临时计数器
            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {
                sb.AppendFormat("update t_location set exportflag='1' where id={0}",strId);
                iCnt += 1;
                if (iCnt == 100)
                {
                    DBUtility.DB.FromSql(sb.ToString()).Execute();
                    sb.Clear();
                    iCnt = 0;
                }
            }
            if (sb.ToString() != "")
            {
                DBUtility.DB.FromSql(sb.ToString()).Execute();
            }

  

原文地址:https://www.cnblogs.com/kuailewangzi1212/p/3360659.html