Deleting SQL

Joined
Mar 13, 2007
Messages
5
Programming Experience
Beginner
Hi

I'm having trouble deleting everything from a table. The connection is ok as the querie to get the data is working. This delete bit just doesn't do anything.
Any ideas ?

Thanks

VB.NET:
 Dim LibraryCommandDel As OleDbCommand
        Dim LibraryAdapterDel As OleDbDataAdapter
        LibraryAdapterDel = New OleDbDataAdapter

        LibraryCommandDel = New OleDbCommand("DELETE FROM Library", Library)

        LibraryAdapterDel = New OleDbDataAdapter()
        LibraryAdapterDel.DeleteCommand = LibraryCommandDel
        LibraryAdapterDel.Update(LibraryTable)
 
I believe you are misunderstanding the purpose of the table adapter. The adapter is there to serve as a bridge between a data table and your database. Unless you change the data table, the adapter will not do anything. Basically, it looks at every row in the data table and sees if it changed. If it did, it calls the corresponding UPDATE, INSERT or DELETE query.

What you do now, is to tell the adapter to use the SQL query that deletes all rows in the table whenever it needs to delete a row (which is found to have been deleted from the data table). However, since you just tell it what action to use in case a row was deleted, but do not delete a row at all, it won't do a thing.

What you should do is to go in the dataset designer and create a new query in the library table adapter that call that SQL query. This will add a new method to the table adapter that will call the query in the database. Then you can refresh your data table.
 
I agree with Stonkie in that this bit of code is very odd, and is most effective at outlining the fact that data access is something of a mystery to you. You can find some good tutorials at the end of the DW2 link in my signature..
 

Latest posts

Back
Top