Solved

What is wrong with this SQL statement?, C# is giving me errors..

Posted on 2008-06-18
6
178 Views
Last Modified: 2013-11-27
I'm new to C#, but this SQL statement is giving me errors; "SQLException Unhandled, Incorrect syntax near "*""

Here is the code:

            SqlCommand command = conn.CreateCommand();
            command.CommandText = "DELETE * FROM MASTER";
            command.CommandType = CommandType.Text;

            SqlDataReader reader = command.ExecuteReader();

Since when can't I use an "*" in a SQL statement?  If I change the statement to a simple "DELETE FROM MASTER" it works fine.  - confused..
0
Comment
Question by:TommyMac501
  • 3
  • 3
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21816441
what is the database? not all database systems allow the * in the DELETE statement.
0
 

Author Comment

by:TommyMac501
ID: 21816490
SQL Server.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21816593
for the reference:
http://msdn.microsoft.com/en-us/library/ms189835.aspx
sql server does not allow the *

while ms access does:
http://msdn.microsoft.com/en-us/library/bb177896.aspx
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:TommyMac501
ID: 21816647
Is that rule only for the SQLDataReader?.  I use the "*" in my queries all the time, including directly through the Query Analyzer.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 21816680
>is that rule only for the SQLDataReader?
no, it's for sql server overall.
note: for the DELETE statement...
for SELECT it is perfectly possible

0
 

Author Comment

by:TommyMac501
ID: 21816734
oops.  duhhh..  Since I usually use the DELETE in conjunction with WHERE, I overlooked it.  I was thinking "TRUNCATE TABLE"..  My Bad...

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

679 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