简体   繁体   中英

how to remove a row from datatable

I'm trying to remove/delete 1 row from datatable which has 100 rows like this:

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! does 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 ?

This should do the trick instead of Delete and AcceptChanges :

Form1.dt.Rows.RemoveAt(i);

Update : Caution when using a DataAdapter and relational data source along with your DataTable . Using Remove modifies the DataTable , but not the actual data source. See https://msdn.microsoft.com/en-us/library/03c7a3zb(v=vs.110).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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