gpt4 book ai didi

c# - 调试在关键字 'where' 附近产生错误的语法

转载 作者:行者123 更新时间:2023-11-29 11:58:06 25 4
gpt4 key购买 nike

我尝试运行以下函数,该函数连接 product 表和 productcategory 表并返回结果。当抛出异常时,调试器会显示查询字符串,我尝试在我的测试 mysql 数据库中运行查询字符串,它可以工作。

CategorizedProduct 是一个模型。我已检查并确保选择列表中的所有字段都与模型中的字段匹配。

我找不到错误所在。

public static List<CategorizedProduct> GetAllCategorizedProducts(string category)
{
using (var conn = Sql.GetConnection())
{
string queryString = "select ProductID,ProductName,ProductType,ProductCategory,CategoryName,Unit,PricePerUnit,IsAvailable,NumberOfUnits,RemainingUnits,WeightPerUnit" +
" from product inner join productcategory where product.ProductCategory = productcategory.CategoryID and CategoryName = \'" + category + "\' order by ProductType;";
return conn.Query<CategorizedProduct>(queryString).ToList();
}
}

最佳答案

试试这个版本:

select ProductID, ProductName, ProductType, ProductCategory,
CategoryName, Unit, PricePerUnit, IsAvailable, NumberOfUnits,
RemainingUnits, WeightPerUnit
from product inner join
productcategory
on product.ProductCategory = productcategory.CategoryID
where CategoryName = \'" + category + "\'
order by ProductType;

我确实认为onjoin之后在MySQL中是可选的,但这可能会解决你的问题。任何其他数据库都需要 on (我认为如果您在 MySQL 中启用了某些 ANSI 设置)。

关于c# - 调试在关键字 'where' 附近产生错误的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32834947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com