PC Review


Reply
Thread Tools Rate Thread

How to delete from a DataSet

 
 
Rik Hemsley
Guest
Posts: n/a
 
      18th Aug 2004
Hi,

I'm trying to delete a row from a recordset, but the database doesn't
seem to be changed at all.

Does this code look incorrect? AFAICT from reading MSDN, it's the Right
Way to delete a row...

MyDataAdapter.Fill(MyDataSet)
Dim r As MyDataSet.MyRow = MyDataSet.MyTable.Rows(0)
MyDataSet.MyTable.RemoveMyTableRow(r)
MyDataAdapter.Update(MyDataSet)

Cheers,
Rik
 
Reply With Quote
 
 
 
 
Rik Hemsley
Guest
Posts: n/a
 
      18th Aug 2004
Rik Hemsley wrote:

> I'm trying to delete a row from a recordset, but the database doesn't
> seem to be changed at all.


That's DataSet, not Recordset, of course.

Rik
 
Reply With Quote
 
Rik Hemsley
Guest
Posts: n/a
 
      18th Aug 2004
Note to self: Re-read the documentation more than twice before posting
to newsgroup.

Rik Hemsley wrote:

> MyDataAdapter.Fill(MyDataSet)
> Dim r As MyDataSet.MyRow = MyDataSet.MyTable.Rows(0)
> MyDataSet.MyTable.RemoveMyTableRow(r)


The above two line should probably be replaced with:

MyDataSet.MyTable.Rows(0).Delete

> MyDataAdapter.Update(MyDataSet)


This seems to work now.

Cheers,
Rik



 
Reply With Quote
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      18th Aug 2004
There are two similar operations on Rows which are easily confused. Calling
Delete() on the required row will mark the row as deleted and will cause it
to be removed from the database when the DataAdapter.Update is run on the
DataSet.

Removing the row from the Rows collection of the DataTable will not remove
the record from the database. This is because the row is immediately taken
out of the DataSet and so when Update runs it is not there to trigger a
Delete statement to be sent to the database.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/...ity/newsgroups

"Rik Hemsley" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Rik Hemsley wrote:
>
>> I'm trying to delete a row from a recordset, but the database doesn't
>> seem to be changed at all.

>
> That's DataSet, not Recordset, of course.
>
> Rik



 
Reply With Quote
 
Rik Hemsley
Guest
Posts: n/a
 
      18th Aug 2004
Peter Foot [MVP] wrote:
> There are two similar operations on Rows which are easily confused. Calling
> Delete() on the required row will mark the row as deleted and will cause it
> to be removed from the database when the DataAdapter.Update is run on the
> DataSet.
>
> Removing the row from the Rows collection of the DataTable will not remove
> the record from the database. This is because the row is immediately taken
> out of the DataSet and so when Update runs it is not there to trigger a
> Delete statement to be sent to the database.


Thanks, that makes perfect sense.

Rik

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Rows of a Dataset BlackSun Microsoft VB .NET 1 27th Jul 2009 05:57 AM
Delete a row in a dataset Toren Valone Microsoft C# .NET 3 26th Aug 2008 11:39 PM
delete row from DataSet?? michaeldcummings@gmail.com Microsoft Dot NET Framework Forms 3 4th Oct 2005 07:01 PM
Re: Delete a table from a dataset Kevin Spencer Microsoft ASP .NET 1 18th Mar 2004 07:46 PM
Performing a delete on a DataSet and writing the DataSet back tothe DB Markus Palme Microsoft ADO .NET 1 26th Nov 2003 05:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:22 PM.