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

ASP Delete Record Syntax Error

Status
Not open for further replies.

KeystoneBlues

Programmer
Jun 14, 2004
9
US
I'm trying to simply delete Records from a MDB database file. I'll post the code below but first I'll tell you that yes I'm a noob but I've been programming other languages before. So I should be too high of maintenance.
To the point:
I have a form that retrieves the data and displays it and a value is given to a radio button. The user then selects which record to delete. So far the process is working.
When the user selects the record (radio button) I get this
*************************
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error in string in query expression 'ID='3'.

/ASP BETA/DeleteCC.asp, line 15
*************************

Ok, line 15 in DeleteCC.asp is
********************
Rs.Open sql, Conn
********************

From what i read that needs to be there but it's after the sql= "Delete * FROM Results WHERE ID='" & ID

Anyway, if anyone can throw me some advise on this I would appreciate it. I'm basically have a system setup so that i can process orders. I need it to sit in a temp database after the order is made.. When I process it I want to be able to transfer it to a master database (leaving out Credit Card info) and removing itself from the temp database. So i split up the 2 actions.. I got it to transfer just fine. Everything is in place but I cannot get it to delete.

Thanks, code is below

DeleteRecord.asp

<meta name="site-config-URL" content="">
Select name to delete.
<%
Dim Conn, Rs, sql
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("secureorderform.mdb")
sql= "SELECT * FROM Results;"
Rs.Open sql, Conn
Response.Write "<FORM name='Delete' method='post' action='DeleteCC.asp'>"
Response.Write "<table border=1 cellspacing=0>"
Response.Write "<tr>"&"<td colspan='3' align='center'>"&"Select a comment to delete and click delete"&"</td>"&"</tr>"
Response.Write "<tr>"&"<th align='center' colspan='2'>"&"Name"&"</th>"&"<th align='center'>"&"Comment"&"</th>"&"</tr>"
Do While not Rs.EOF
Response.Write ("<tr>")
Response.Write ("<td>"&"<input type='radio' name='ID' value="&Rs("ID")&">"&"</td>")
Response.Write ("<td>"&Rs("CUST_FIRST_NAME")&"</td>")
Response.Write ("<td>"&Rs("CUST_LAST_NAME")&"</td>")
Response.Write ("</tr>")
Rs.MoveNext
Loop
Response.Write("<tr>"&"<td colspan='3' align='center'>"&"<input type ='submit' name='submit' value='Delete' onClick='return validate();'>"&"</td>"&"</tr>")
Response.Write "</table>"
Response.Write "</form>"
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
%>




DeleteCC.asp
<meta name="site-config-URL" content="">
<%
Dim ID
ID = Request.Form("ID")
if ID="" then
Response.Write "You did not select a name to delete!"
Else
Dim Conn
Dim Rs
Dim sql
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("secureorderform.mdb")
sql= "Delete * FROM Results WHERE ID='" & ID
Rs.Open sql, Conn
Conn.Close
Set Conn = Nothing
Response.Write "Successfully Deleted"
End If
%>

Thanks,
Allen
 
Just looks like a small syntax error. Try this:
Code:
sql= "Delete * FROM Results WHERE ID='" & ID [COLOR=red]& "'"[/color]
You just needed to close the parentheses. :)

------------------------------------------------------------------------------------------------------------------------
"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair."
--Dou
 
Thanks for taking the time to show me that. You were correct. That gets me past this hump... And believe me I'm very happy to be moving forward now. Not sure how I missed that, was up all night pulling my hair out, so much appreciated.

I'm getting another error (bottom) but i should be able to fix this one.

Just for grins here's my new prob just incase you might have a quick solution for this one as well..
I think it has something to do with how I have my records in the database.
Can I use the ID field only, to delete the complete record?
would defining the ID field conflict with any standard variables in my asp code? The ID column will be the order number for the user to refer to when inquiring on an order.
********************
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

/ASP BETA/DeleteCC.asp, line 15
**********************
 
Presumably your ID field is the primary key field (or equivalent), so you should be able to use this as your filter for your DELETE statement. Typically, a data type mismatch indicates that you have an alpha string where you should only have numeric or that you may be trying to pass a null. Not sure if that is the case here, but something to think about.

Also, don't think this is necessarily causing your current problem, but you probably don't need to create a recordset for your DELETE statement, you could just use a Conn.Execute to run your statement.

------------------------------------------------------------------------------------------------------------------------
"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair."
--Dou
 
Hmm, I'll check that out for sure....


Thanks again for your time,
al
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top