Solved

ASP DELETE Statement

Posted on 2002-04-26
5
497 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 100 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:Silvers5
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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 have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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/…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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