ds.Tables[0].Rows.RemoveAt(i)数据库表格删除行

不要在循环里使用myDataTable.Rows.RemoveAt(i).因为每删除一行后.i的值会增加,但行数会是减少了.这么做一定会出错.
因此要遍历数据,使用Remove方式时,要倒序的遍历
int count = ds.Tables[0].Rows.Count;
for (int i = count -1; i >=0; i--)

ds.Tables[0].Rows.RemoveAt(i);
}

 

注;摘抄自大神博客https://blog.csdn.net/xiangcns/article/details/45136091

posted on 2018-03-28 15:12  七七2020  阅读(262)  评论(0编辑  收藏  举报

导航