DataSet 删除数据 不更新数据库

it2022-05-09  19

string SelectCommand = string.Format("select top 1 Id, PiaoJuPiaoHao, DaoZhanDianMian, HuoWuPinMing, JianShu, ZhongLiang, TiJi, ZhuangTai, FaZhanDianMian, CheChi from FaZhanPiaoJuBiao");//定义数据样式         bool flag = false;

        for (int i = GridView1.Rows.Count-1; i <= GridView1.Rows.Count-1; i--)//从下向上遍历         {           CheckBox box =  GridView1.Rows[i].FindControl("CheckBox1") as CheckBox;           flag = box.Checked;           if (flag == true)           {               dt.Tables[0].Rows.RemoveAt(GridView1.Rows[i].RowIndex);               //dt.AcceptChanges();              }           if (i == 0)           {               break;           }         }          GridView1.DataSource = dt.Tables[0];

              GridView1.DataBind();

 

为什么 从下向上遍历呢  因为 数据集再循环中 删除一条语句 其他的索引下标就随着改变 所以 从下向上遍历

转载于:https://www.cnblogs.com/zt04985807/archive/2009/01/04/1367893.html

相关资源:数据结构—成绩单生成器

最新回复(0)