string sqlStr0 = "select ProName,ProID,MemberPrice,Price from Products where ProID in (@GiftsID)";
SqlParameter[] pms ={
       new SqlParameter("@GiftsID",dsAcMess.Tables[0].Rows[0]["GiftsID"])
       };
//dsAcMess.Tables[0].Rows[0]["GiftsID"]==76,77,79,83,84,87,94,96,97,98,99
//数据库中ProID 是Int类型的 报错类容:
在将 nvarchar 值 '76,77,79,83,84,87,94,96,97,98,99' 转换成数据类型 int 时失败求解改怎么解决呢?我想组成这样的sql语句select ProName,ProID,MemberPrice,Price from Products where ProID in (76,77,79,83,84,87,94,96,97,98,99)

解决方案 »

  1.   

    不使用参数化查询
    或使用charindex(','+ltrim(ProID)+',',','+@GiftsID+',')>0
      

  2.   

    建议你直接去构建SQL,不要用这种.NET的传参数方式,如
    string sqlStr0 = "select ProName,ProID,MemberPrice,Price from Products where ProID in (" + GiftsID + " )";除非你有什么必要的原因一定要使用你的那种方式,这种情况我觉得比较适合直接构建
      

  3.   

    用存储过程
    create proc xxxx
    @GiftsID varchar(100)
    as begin
    set @sql='select ProName,ProID,MemberPrice,Price from Products where ProID in ('+@GiftsID+')'
    exec(@sql)
    end
      

  4.   

    在将 nvarchar 值 '76,77,79,83,84,87,94,96,97,98,99' 转换成数据类型 int 时失败这样的话,GiftsID的值得是string
      

  5.   

    string sqlStr0 = "select ProName,ProID,MemberPrice,Price from Products where ProID in (@GiftsID)";
    SqlParameter[] pms ={
           new SqlParameter("@GiftsID",dsAcMess.Tables[0].Rows[0]["GiftsID"])
           };
    //dsAcMess.Tables[0].Rows[0]["GiftsID"]==76,77,79,83,84,87,94,96,97,98,99
    //数据库中ProID 是Int类型的 把存储过程的@GiftsID设置成varchar类型
      

  6.   

    知道是string的  现在在找解决方案呢