Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2006

Tip: Looking for answers? Try searching our database.

ADO.NET explanation of deleting rows from DB please?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sherifffruitfly - 31 Oct 2006 19:58 GMT
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
Peter Bromberg [C# MVP] - 31 Oct 2006 20:06 GMT
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

Signature

Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

> Hi,
>
[quoted text clipped - 20 lines]
>
> cdj
sherifffruitfly - 31 Oct 2006 20:17 GMT
Peter Bromberg [ C# MVP ] wrote:
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.