DataSet.Clear()

M

mick

I`ve been trying to get to know ADO.net lately and I wonder if anyone can
explain why the following does not work -

myDataSet.Clear();
myDataSet.AcceptChanges();
myTableAdapter.Update(myDataSet);

If you clear the dataset and then do the update shouldnt the database be
cleared as well. When I tried this the contents of the database are still
there when I rerun my app.

What I ended up doing was iterating throw the dataset and deleting row by
row but I`m curious why the above doesnt work.

TIA,

mick
 
M

Miha Markic

In your case Clear removes all the information from *Dataset* thus Update
won't do anything. Update does its things based on the rows in their
RowState.
 
M

mick

Miha Markic said:
In your case Clear removes all the information from *Dataset* thus Update
won't do anything. Update does its things based on the rows in their
RowState.

I`ve been reading a bit more and would just like you confirm that I
understand it correctly -

When I use Clear on the DataSet it actually clears all of the entries but if
I use Delete it just "marks" entries for deletion but does not actually
perform any deletion until the update. Is this correct?

mick
 
M

Miha Markic

I`ve been reading a bit more and would just like you confirm that I
understand it correctly -

When I use Clear on the DataSet it actually clears all of the entries but
if I use Delete it just "marks" entries for deletion but does not actually
perform any deletion until the update. Is this correct?

Yes, it will mark existing rows with RowState = Deleted. If the row doesn't
exist in database (it has been added in memory) it will be removed.

HTH,
 
M

mick

Miha Markic said:
Yes, it will mark existing rows with RowState = Deleted. If the row
doesn't exist in database (it has been added in memory) it will be
removed.

Thanks Miha.

mick
 

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