简体   繁体   English

如何从数据表中删除行

[英]how to remove a row from datatable

I'm trying to remove/delete 1 row from datatable which has 100 rows like this: 我试图删除/删除从1行datatable ,其具有100行是这样的:

Form1.dt.Rows[i].Delete();
Form1.dt.AcceptChanges();

but further down when i get the count of the rows of the table like : 但是当我得到表的行数时进一步下降:

int rc = Form1.dt.Rows.Count;

the rc still returns 100! rc仍然返回100! does Form1.dt.Rows[i].Delete(); 是否执行Form1.dt.Rows[i].Delete(); clear the row and leave it empty there or delete the row completely from table? 清除该行并将其留在那里还是将其完全从表中删除? and how can i remove that row form the dt ? 以及如何从dt删除该行?

This should do the trick instead of Delete and AcceptChanges : 这应该可以解决问题,而不是DeleteAcceptChanges

Form1.dt.Rows.RemoveAt(i);

Update : Caution when using a DataAdapter and relational data source along with your DataTable . 更新 :在将DataAdapter和关系数据源与DataTable一起使用时的警告。 Using Remove modifies the DataTable , but not the actual data source. 使用Remove会修改DataTable ,但不会修改实际的数据源。 See https://msdn.microsoft.com/en-us/library/03c7a3zb(v=vs.110).aspx 参见https://msdn.microsoft.com/zh-cn/library/03c7a3zb(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM