Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-06-18
6
Medium Priority
?
183 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 500 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

963 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