Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

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

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
TommyMac501
Asked:
TommyMac501
  • 3
  • 3
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what is the database? not all database systems allow the * in the DELETE statement.
0
 
TommyMac501Author Commented:
SQL Server.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
TommyMac501Author Commented:
Is that rule only for the SQLDataReader?.  I use the "*" in my queries all the time, including directly through the Query Analyzer.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>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
 
TommyMac501Author Commented:
oops.  duhhh..  Since I usually use the DELETE in conjunction with WHERE, I overlooked it.  I was thinking "TRUNCATE TABLE"..  My Bad...

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

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

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