PDA

View Full Version : Record will not delete


iamdavid
06-14-2011, 05:40 PM
HERES THE SCRIPT THAT DON'T WORK:
Dim myConn, rs, mysql
SET myConn = CreateObject("ADODB.Connection")
set rs=Server.CreateObject("ADODB.recordset")

MyConn = "Provider=SQLOLEDB;Data Source=tcp:*******2.discountasp.net;Initial Catalog=SQL2008_******s;User ID=SQL2008_******_fhs_user;Password=******;"
[ignore the **** in MyConn of course.]
cid = request.form("rec_id")
mysql = "DELETE FROM " & Request.Form("Table_Name") & " WHERE id = '" & cid & "';"

MyConn.Execute mysql

AFTER FORM SUBMISSION THIS IS WHAT IS RETURNED:
table = Visitors record id = 39 [<-from response.write request.form("table_name") & " record id = " & cid]

DELETE FROM Visitors WHERE id = '39';[<-- from request.write mysql]

HERES THE ERROR PRODUCED:
Microsoft VBScript runtime error '800a01a8'

Object required: 'Provider=SQLOLEDB;Da'

/delete_record.asp, line 46
The connection string MyConn works for every thing else like INSERT, SELECT but not DELETE. Anyone have a clue?:confused:

wisemx
06-15-2011, 03:32 AM
Two things I can think of;
1) Change "id" to this -> WHERE [id]
2) Catch that form value and make sure you are getting something for: request.form("rec_id")

i.e. <%= cid %>

iamdavid
06-15-2011, 05:17 AM
I changed the id to [id] but still did not work.
What did work was changing from MyConn.Execute to rs.Open method.
For others reading this you have to include these lines not found in my original post:
set rs=Server.CreateObject("ADODB.recordset")
Rs.Open mysql, MyConn

And remove the line:
MyConn.Execute mysql

Thank You.

wisemx
06-15-2011, 08:40 AM
Good job ;-)