CodeMonkey
CodeMonkey

Reputation: 2523

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?

Upvotes: 0

Views: 1199

Answers (1)

Vlad
Vlad

Reputation: 1919

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

Upvotes: 5

Related Questions