上面那个sql语句 where id in (4951,4952,4953,4954,4955,4956),MSSQL可以执行。下面那个sql语句 where id in ('4951,4952,4953,4954,4955,4956'),肯定报错撒!

解决方案 »

  1.   

    不失败鬼来了
    '4951,4952,4953,4954,4955,4956'你告诉我能转成int吗?转过来回事什么样子?
      

  2.   

      下面那个怎么改成where id in (4951,4952,4953,4954,4955,4956)呢?
      

  3.   

     public static bool UpdateBookCategorie(string ids, string categorieId)
            {
                string sql = "proc_uptate_bookCategory";
                SqlParameter[] para = new SqlParameter[]{
                    new SqlParameter ("@CategoryId",categorieId),
                    new SqlParameter ("@ids",ids)
                    };
                int count = DBHelper.ExecuteNonQuery(sql, para);            if (count == 1)
                {
                    return true;
                }
                return false; 
            } 
      

  4.   

       那sql语句怎么写才能用存储过程呢?
      

  5.   

    最笨的改成这样
    string sql ="update Books set CategoryId = @ categorieId  
    where cast(id as nvarchar(10)) in(@ids)"; 然后把@ids的值传成4951','4952','4953','4954','4955','4956
    (没有开发环境,没办法帮你试)
      

  6.   


    用存储过程不一样嘛?  int的数据类型有多长呀?我不记得了,我感觉不会有你那么大。
      

  7.   

    你在把参数传入@ids之前,就把ID的值组合成'1','2','3'这种格式的,然后当做参数传入存储过程。这样
    Set sql ='update Books set CategoryId = @categorieId  where id in ('''+@ids+''')'就行了,注意在SQL里两个单引号代表一个'。 还有ID的字符串组最后要把","去掉
      

  8.   

    string sql ="update Books set CategoryId = @categorieId  where 
    CHARINDEX(','+LTRIM(id)+',',','+@ids+',')>0"; 
      

  9.   

    呵呵   可以了   
    谢谢大家        
    浪么给分呢?
    我用了个笨办法   
    ALTER PROCEDURE [dbo].[Pro_UpdateBooksCatagory]
    -- Add the parameters for the stored procedure here
    @Id nvarchar(100),
    @CatagoryId int 
    AS
    BEGIN
    declare @nid nvarchar(4)
        declare @i int 
        declare @j int
       set @i=1
       set @j=5 
       while(1=1)
    begin
      if(@Id!='')
    begin
               set @nid=SubString(@id,@i,@j)
             if( @nid!='')
    begin
                   Update Books set CategoryID=@CatagoryId where Id =@nid
                    set @i=@i+5
                    set @j=@j+4
                set @nid=''
    end
             else
               break
    end
            end
    END