无法将浮点值传递为sqlparameter

时间:2013-07-20 13:30:26

标签: sql sql-server-2008

我的查询就像这样

    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 [Kontorting_Umbraco_DB].[dbo].[tbl_Projects] " +
  " where [Category] like '%' + @Category + '%' " + 
  "   and Country like'%'+ @country+'%' " + 
  "   and value like '%'+@Value+'%' " + 
  "        order by CreatedDate asc",

              new SqlParameter("@Category","water") ,
              new SqlParameter("@Country", "Bahrain"),
              new SqlParameter("@Value", 1000));

在此代码中,“值”字段在DB中浮动。当我执行此操作时,我收到错误

  

将varchar值'%'转换为数据类型int时,转换失败。

任何人都可以告诉我如何使用像float一样的查询

1 个答案:

答案 0 :(得分:2)

你在做什么

value like '%'+@Value+'%'

,其中valueint

LIKE only works with expressions of character data type.

你可以做到

convert(nvarchar(100), value) like '%' + convert(nvarchar(100), @Value) + '%'

代替。

请注意,您可能需要调整数据的长度(目前为100)。