ADO.NET explanation of deleting rows from DB please?

  • Thread starter Thread starter sherifffruitfly
  • Start date Start date
S

sherifffruitfly

Hi,

I want to delete rows from my database. So I download them to a
dataset, and then discover the following.

This does not work:

dataset["tablename"].Rows.Clear();
dataadapter.Update(dataset, "tablename");


This does work:

foreach (DataRow dr in dataset["tablename"].Rows)
{
dr.delete();
}
dataadapter.Update(dataset, "tablename");

I don't know enough about what's going on "underneath the hood" - why
doesn't the first one work?

Thanks for any info,

cdj
 
The DataAdapter's Update Method relies on the RowState of each row in the
datatable to tell whether to perform an update, insert, or delete. Since in
the first case you've cleared out all the DataRows, it therefore has nothing
to do.
Peter
 
Peter said:
The DataAdapter's Update Method relies on the RowState of each row in the
datatable to tell whether to perform an update, insert, or delete. Since in
the first case you've cleared out all the DataRows, it therefore has nothing
to do.
Peter

Oooh. So is this right, in other words: the word "delete" in
DataRow.Delete *means* delete only from the DB's perspective. If I
followed up with a DataTable.rows.rowcount(), this would be unaffected
by DataRow.delete?

Whereas on the other hand, DataTable.Rows.Clear() means delete the rows
from the application's perspective. In this case,
DataTable.rows.rowcount() would be affected?

Is that kinda the idea?

Thanks for the info!

cdj
 

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

Back
Top