Solved

Deleting Rows from a Database in VB2005

Posted on 2006-07-04
1
223 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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

13 Experts available now in Live!

Get 1:1 Help Now