Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Deleting Rows from a Database in VB2005

Posted on 2006-07-04
1
Medium Priority
?
253 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

885 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