?
Solved

Problem deleting records from SQL table

Posted on 2009-04-30
3
Medium Priority
?
198 Views
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
 
        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
Comment
Question by:gwosgood
  • 2
3 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 24271883
remove the *

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

Author Comment

by:gwosgood
ID: 24271979
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 24272087
>>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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

839 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