0
conn.Open();
String sql = "select CATEGORIES.CAT_NAME,PRODUCTS.PRO_MODEL,PRODUCTS.PRO_NAME,PRODUCTS.PRO_PRICE,PRODUCTS.PRO_IMAGE,PRODUCTS.PRO_DESCRIPTION,PRODUCTS.PRO_STATUS,PRODUCTS.PRO_ACTIVE" +
"from PRODUCTS INNER JOIN CATEGORIES on PRODUCTS.CAT_ID = CATEGORIES.CAT_ID";

我的查询 SQL 在 MYSQL Server 中运行良好,但在 C# 代码中有错误 关键字“INNER”附近的语法不正确。希望尽快得到答复

4

3 回答 3

5

您需要在 (和) 字符串连接之间添加空格。.PRO_ACTIVE""from

.PRO_ACTIVE " + "from...

所以你的查询应该是:

String sql = "select CATEGORIES.CAT_NAME,PRODUCTS.PRO_MODEL,PRODUCTS.PRO_NAME,PRODUCTS.PRO_PRICE,PRODUCTS.PRO_IMAGE,PRODUCTS.PRO_DESCRIPTION,PRODUCTS.PRO_STATUS,PRODUCTS.PRO_ACTIVE" 
+ " " +//explicit space 
"from PRODUCTS INNER JOIN CATEGORIES on PRODUCTS.CAT_ID = CATEGORIES.CAT_ID";
于 2013-02-19T09:14:11.670 回答
3

您需要在字符串的第一行末尾有一个空格——C# 不会放入换行符。

于 2013-02-19T09:14:20.703 回答
2

将其更改为:

String sql = "select CATEGORIES.CAT_NAME,PRODUCTS.PRO_MODEL,PRODUCTS.PRO_NAME,PRODUCTS.PRO_PRICE,PRODUCTS.PRO_IMAGE,PRODUCTS.PRO_DESCRIPTION,PRODUCTS.PRO_STATUS,PRODUCTS.PRO_ACTIVE" +
    " from PRODUCTS INNER JOIN CATEGORIES on PRODUCTS.CAT_ID = CATEGORIES.CAT_ID";

“..PRODUCTS.PRO_ACTIVE”和“来自 PRODUCTS..”之间缺少空格

于 2013-02-19T09:14:46.943 回答