Solved

ASP DELETE Statement

Posted on 2002-04-26
5
485 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Classic ASP migration directions 7 67
API Location, separating out information 10 46
Dreamweaver server behavior gone 6 110
Use a variable for Class Name in Classic ASP 4 46
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

21 Experts available now in Live!

Get 1:1 Help Now