[英]Debugging yields incorrect syntax near keyword 'where'
I have the following function that I am trying to run that joins a product
table and a productcategory
table and return the results. 我尝试运行以下功能,该功能将
product
表和product
productcategory
表联接productcategory
并返回结果。 The debugger, when exception is thrown, displays the query string and I have tried running the query string in my test mysql database and it works. 当引发异常时,调试器显示查询字符串,并且我尝试在我的测试mysql数据库中运行查询字符串,并且该调试器有效。
The CategorizedProduct
is a model. CategorizedProduct
是一个模型。 I have checked and made sure that all the fields in the select
list match the fields in the model. 我已经检查并确保
select
列表中的所有字段都与模型中的字段匹配。
I cannot find where the error is. 我找不到错误所在。
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();
}
}
Try this version instead: 试试这个版本:
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;
I do think that the on
is optional in MySQL after join
, but this might fix your problem. 我认为,在
on
是MySQL后,可选的join
,但是这可能会解决您的问题。 The on
is required by any other database (and I think if you have certain ANSI settings on in MySQL). 其他任何数据库都需要
on
(并且我认为如果您在MySQL中具有某些ANSI设置)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.