Link to home
Start Free TrialLog in
Avatar of Saqib Khan
Saqib KhanFlag for United States of America

asked on

ASP DELETE Statement

Hi, Can anyone on this earth Help me out with this code pleaseeeeeeeeeeeeeee, whats wrong with this code why my Delete statment is not working( Please ignore the &_ to continue the code in below example)



Dim conn
Set conn = Server.Createobject("ADODB.CONNECTION")
conn.open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\wwwroot\dma110\final\final.mdb"
dim sql

sql = "DELETE * FROM about WHERE fname="&Request.QueryString("removee")
conn.execute(sql)

%>
Avatar of hongjun
hongjun
Flag of Singapore image

Try this

Dim conn
Set conn = Server.Createobject("ADODB.Connection")
conn.open "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\dma110\final\final.mdb;"
dim sql

sql = "DELETE FROM about WHERE fname= '" & replace(Request.QueryString("removee"),"'","''") & "'"
conn.execute(sql)

conn.close
set conn = nothing
%>


hongjun
Also make sure Request.QueryString("removee") actually does have value.

hongjun
Avatar of Saqib Khan

ASKER

Hurrayyyyyyy it worked.. Please Can u Explain it to me About that Quoating things i would really Appericate that.And Also a little Brief Explaination for this code.
ASKER CERTIFIED SOLUTION
Avatar of hongjun
hongjun
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michel Sakr
give points to hongjun:

Dim conn 'this will declare our variable.. a good practice 4 faster performance
Set conn = Server.Createobject("ADODB.Connection") 'creating the connection object
conn.open "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\dma110\final\final.mdb;" 'opening the connection to the database and specifying the connection string
dim sql 'declaring

sql = "DELETE FROM about WHERE fname= '" & replace(Request.QueryString("removee"),"'","''") & "'"  'query string to run against database
conn.execute(sql) 'querying the databse

'cleaning part
conn.close 'closing the connection
set conn = nothing ' destroying the connection object
%>


about replacing the single quote, single quotes are delimiters in SQL (the language), so we double them '' as an escape sequence otherwise if the value of our variable contains O'connor it will throw an error (this site has a similar replace now otherwise it would throw me the error when i post this message)