Cannot delete from SQL Server database

Posted on 2011-10-26
Last Modified: 2012-05-12
I'm trying to delete entries from my SQL Server database but I get the error message:
Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near '*'.
/AcSec/delete.asp, line 19

I am using classic ASP. Please see my 'delete.asp' attached.
I'm doing it like this:
<a href="Update.asp?key=<%= rs("ID")%>">Delete</a>
This method worked fine when I was using MS Access database, but since I switched to SQL Server it doesn't work. Would you please let me know how to change the code in the 'delete.asp' in order to be able to delete entries? Thank you very much for your help.
'Dimension variables
Dim adoCon              'Holds the Database Connection Object
Dim strSQL              'Holds the SQL query for the database
Dim lngRecordNo         'Holds the record number to be deleted

'Read in the record number to be deleted
lngRecordNo = CLng(Request.QueryString("ID"))

'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "Provider=sqloledb;SERVER=DASTVMSQLCX01;DATABASE=AcSec;UID=AcSecUser;PWD=acsec102611;"

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "DELETE * FROM Results WHERE ID=" & lngRecordNo

adoCon.Execute strSQL

'Reset server objects
Set adoCon = Nothing

'Return to the delete select page incase another record needs deleting
Response.Redirect "All.asp"

Open in new window

Question by:baxtalo
    LVL 39

    Accepted Solution

    SQL Server syntax is:

    DELETE  FROM Results WHERE ID=" ...

    and not

    DELETE * FROM Results WHERE ID="

    Author Closing Comment

    Thank you very much, perfect solution.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now