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   七七2020  阅读(277)  评论(0编辑  收藏  举报

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示