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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Problem

Status
Not open for further replies.

csiwa28

Programmer
Apr 12, 2001
177
I am able to select information but, I am having trouble with a delete SQL statment. I am getting a
'Unable to delete from specified table" error message. What am I missing?



Set oConn = Server.CreateObject("ADODB.Connection")

MdbFilePath = Server.MapPath("AMCA.mdb")

oConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"

SQL_query = "DELETE FROM ORDERS WHERE PRODUCT_ID=" & PRODUCT_ID

Set oRS = oConn.Execute(SQL_query)
 
Don't use a recordset to DELETE records:

Set oRS = oConn.Execute(SQL_query)

Should be simply:

oConn.Execute(SQL_query)

This is a common mistake that many people make. For some reason, it's assumed that a recordset must be used for every single type of database operation. This is a myth.

Indeed, a recordset should ONLY be used to return some data for output on your screen. INSERT, DELETE, and UPDATE operations should be completed either by a straight con.execute() call or via a stored procedure -- depending on which is more efficient in your particular situation.

hope that clears it up! :)
Paul Prewett
penny.gif
penny.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top