[英]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: 所以我试图用C#代码来做到这一点:
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).
不同的DBMS对标识符(例如列名)使用不同的引用系统。 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.
此外,即使某些DBMS允许您省略它,也请使用AS指定符。
(PS: In the second example, the quote character is the backtick, generally on the same key as the tilde (~) on US keyboards). (PS:在第二个示例中,引号字符是反引号,通常与美式键盘上的波浪号(〜)位于同一键上)。
您缺少一个as
:
string sqlqry1 = "SELECT p_Name as \"Prodcut Name\" from items";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.