Solved

ASP DELETE Statement

Posted on 2002-04-26
5
482 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:adilkhan
  • 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:adilkhan
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now