简体   繁体   中英

Help with SQL query in C#

I'm trying to rename the columns. The syntax should be the column name between double quotes incase of two words, like this:

SELECT p_Name "Product Name" from items

So I'm trying to do it in C# code like this:

string sqlqry1 = "SELECT p_Name \"Prodcut Name\" from items";

But I get an error:

Syntax error (missing operator) in query expression 'p_Name "Prodcut Name"'.

It seems am having somthing wrong with the quotes, but I can't figure out.

You don't specify what database you're using. Different DBMSes use different quoting systems for identifiers (like column names). Try:

 SELECT p_Name AS [Product Name] FROM items

or

 SELECT p_Name AS `Product Name` FROM items

which are two common systems. Also, use the AS specifier even though some DBMSes allow you to leave it out.

(PS: In the second example, the quote character is the backtick, generally on the same key as the tilde (~) on US keyboards).

您缺少一个as

string sqlqry1 = "SELECT p_Name as \"Prodcut Name\" from items";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM