2

我的内联 sql 查询是这样的

DataSet ds =  SqlHelper.ExecuteDataset(GlobalSettings.DbDSN, CommandType.Text, 
   "SELECT TOP 1000 [ID],[Project],[Owner],[Consultant],[Contractor],[Value],
      [Level1], [Level2] ,[Status] ,[Category]  ,[Country],[CreatedDate],
      [CreatedByID], [CreatedByName] 
    FROM [DBname].[dbo].[tbl_Projects] 
    where [Category] like %@Category% 
      and Value=1000 
      and Country like'%Bahrain%' 
    order by CreatedDate",
new SqlParameter("@Category","oil")  );

对我来说一切都很好。但它会引发错误

System.Data.SqlClient.SqlException: Incorrect syntax near 'Category'.

我相信这是我在使用类似查询时做错的事情。任何人都可以指出出了什么问题吗?

4

1 回答 1

2

我认为这应该有效

... LIKE '%' + @Category + '%'

参看。T-SQL 和 WHERE LIKE %Parameter% 子句

于 2013-07-19T11:12:00.353 回答