Problem deleting records from SQL table

Posted on 2009-04-30
Last Modified: 2012-05-06
Greetings experts,

I have a function within my application that purges all records out of a table in my SQL 2005 db.  Everything appears fine within the code, I use a SQLCommand and call the ExecuteNonQuery method.  For some reason, it is being flagged as an error within my SQL string.

Problem code:

ReturnValue = DeleteCmd.ExecuteNonQuery

Gives me error message:

Incorrect syntax near '*'

Ive verified that I have the correct spelling of my SQL Table.

Any help at all in this matter would be greatly appreciated, I would very much like to wrap this up.
Public Function DeleteAll() As Integer

        Dim RC As Integer = 2

        Dim DeleteCmd As New SqlCommand("Delete * From PSWCreditComments", connection)

        Dim ReturnValue As Integer


        ReturnValue = DeleteCmd.ExecuteNonQuery

        If ReturnValue > 0 Then

            RC = 0


            RC = 2

        End If


        Return RC

End Function

Open in new window

Question by:gwosgood
    LVL 69

    Accepted Solution

    remove the *

    Dim DeleteCmd As New SqlCommand("Delete From PSWCreditComments", connection)
    LVL 2

    Author Comment

    Ah, thank you.  That seemed to do the trick.
    I also needed to extend the default command timeout to 100

    Any idea why I would need to remove that part?
    LVL 69

    Expert Comment

    by:Éric Moreau
    >>I also needed to extend the default command timeout to 100
    DeleteCmd.TimeOut = 100

    >>Any idea why I would need to remove that part?
    The * in the Select statement says to select all the columns. In a Delete statement, a * does no make sense. The complete row is deleted (not just a couple of fields). The * in the Delete statement is accepted/ignored in Access but other engine are not accepting it.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now