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

原文地址:https://www.cnblogs.com/webttt/p/8663976.html