Solved

Deleting Rows from a Database in VB2005

Posted on 2006-07-04
1
230 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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