• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Problem deleting records from SQL table

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
 
        connection.Open()
 
        ReturnValue = DeleteCmd.ExecuteNonQuery
        If ReturnValue > 0 Then
            RC = 0
        Else
            RC = 2
        End If
 
        connection.Close()
        Return RC
 
End Function

Open in new window

0
gwosgood
Asked:
gwosgood
  • 2
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
remove the *

Dim DeleteCmd As New SqlCommand("Delete From PSWCreditComments", connection)
0
 
gwosgoodIT MgrAuthor Commented:
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?
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now