Solved

Deleting Rows from a Database in VB2005

Posted on 2006-07-04
1
227 Views
Last Modified: 2010-04-23
I am having trouble permanently deleting records from a database using VB2005.  The dataset, tableadapter, and binder are defined. I can successfully add records to the source database (permanently), but cant delete them.  

Any idea why the following doesnt work?

MyTableTableAdapter.Fill(MyDataset.MyTable)
MyDataset.MyTable.rows.clear    
MyDataset.myTableAdapter.Update(MyDataset.MyTable)

The deletions occur in the temorary dataset created by VB, but not in the source database.

0
Comment
Question by:BW999
1 Comment
 
LVL 34

Accepted Solution

by:
Sancler earned 250 total points
ID: 17038503
A DataAdapter (hence a TableAdapter) works, when .Update is called, by looking that the .RowState flags of the rows in the relevant datatable.  If any of those are set to "Deleted" then it will send the appropriate "Delete" command to the database.  What you are doing with

MyDataset.MyTable.rows.clear    

is REMOVING all the rows that you have just filled with the .Fill command.  So when you call .Update, there are no rows, hence no .Rowstate flags, hence nothing done.

If you want to mark all rows for deletion then you need something like

MyTableTableAdapter.Fill(MyDataset.MyTable)
For Each dr As DataRow in MyDataSet.MyTable.Rows
    dr.Delete
Next
MyDataset.myTableAdapter.Update(MyDataset.MyTable)

Roger
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now