Solved

Deleting Rows from a Database in VB2005

Posted on 2006-07-04
1
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

734 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