Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO.Net and DeleteCommand

Status
Not open for further replies.

teqmem

Programmer
Nov 26, 2004
114
US
Hello,

I'm new to ADO.Net and need help on using ADO.Net to delete records from an Oracle database. Based on a book I read, I need to set my adapter's DeleteCommand and the deletes on a dataset would be saved onto the database.

Below is a sample code of how I'm trying to do it. I can see that the row is deleted from the dataset but the delete is not propagated to the database when I call the adapter's Update. What am I missing? I have also defined my InsertCommand and UpdateCommand and the inserts and updates are applied on the dataset and the database properly.

Thank you.
Code:
Dim ds as Dataset = new Dataset("ds")
Dim objAdapter As Oracle.DataAccess.Lite.OracleDataAdapter = New OracleDataAdapter

cmdSel = CreateCommand()
cmdSel.CommandText = "SELECT ..."

objAdapter.SelectCommand = cmdSel
objAdapter.Fill(ds, "tab")

' -- delete any item from dataset
ds.Tables("tab").Rows.RemoveAt(4)

cmdDel = CreateCommand()
cmdDel.CommandText = "DELETE ..."

objAdapter.DeleteCommand = cmdDel
objAdapter.Update(ds, "tab")
 
Try changing the last line:

Code:
...

objAdapter.DeleteCommand = cmdDel
objAdapter.DeleteCommand.ExecuteNonQuery()

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
I got an error "driver not capable of this operation" when I tried the last suggestion. I verified that my DELETE statement works.
 
I don't see where you have added paramters and set their .SourceColumn propertiers. The dataadapter needs to get information from the command on which parameter goes with which column--it doesn't pick them up by the name alone, because you could conceivably name them 1,2,3,4, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top