Re: Delete or RemoveAt

T

touf

Thanks Stephan, but In my case, I need that it will be removed from the
dataset before to update.
I have in my dataset many customers, and the user can navigate between and
modify as he like before to save all.
so if I delete the customer 0 for example, I need that the old number 1
become number 0 in the dataset.
Now it gives me an error because the dataset contains the deleted row in
position 0.
 
C

Charles Rumbold

You need to call DataSet.AcceptChanges - which is what the data adator
is. So like:

foreach( DataRow row in myDataSet.Tables[0] )
if( myTestToDelete(row) )
row.Delete();
myDataSet.AcceptChanges();

You can use remove provided you do not have an enumerator open, or use
one after. AcceptChanges is called after you have finished with the
enumerator. The row don't delete until the last call.
 
D

David Sceppa

You might want to consider using a DataView. When you mark
the row as deleted, the row must remain in the DataTable in order
to submit the pending change to the database when you call
DataAdapter.Update. So, calling DataRow.Delete will not change
DataTable.Count. However, deleted rows are not visible in a
DataView by default. After calling DataView(0).Delete,
DataView(0) will return row 1 in the DataTable rather than row 0.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.
 
T

touf

Hi,
Thanks a lot,

I've noticed that the problem doesn't happen when using dataviews.. it is a
good idea to always use datatable.defaultview.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top