DataSet.Clear()

  • Thread starter Thread starter mick
  • Start date Start date
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
 
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.
 
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
 
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,
 
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
 
Back
Top