?
Solved

ASP DELETE Statement

Posted on 2002-04-26
5
Medium Priority
?
503 Views
Last Modified: 2006-11-17
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)

%>
0
Comment
Question by:Saqib Khan
  • 3
5 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 6972748
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
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6972749
Also make sure Request.QueryString("removee") actually does have value.

hongjun
0
 
LVL 23

Author Comment

by:Saqib Khan
ID: 6972754
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.
0
 
LVL 33

Accepted Solution

by:
hongjun earned 400 total points
ID: 6972760
You need the ' for all string fields. If it is not needed for integer fields. The replace function is to prevent syntax error in case the string values has single quotes in it. The replace function replaces every single occurences of single quotes with 2 single quotes.

hongjun
0
 
LVL 20

Expert Comment

by:Michel Sakr
ID: 6972761
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)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question