批量删除

 public int Delete(string IdList)   
        {   
            ////存储过程解决方案   
            try  
            {   
                SqlParameter[] parameters = {   
                    new SqlParameter("@IdList", SqlDbType.VarChar,250)};   
                parameters[0].Value = IdList;   
                int rows = 0;   
                DbHelperSQL.RunProcedure("pro_Child_B_JDel", parameters,out rows);   
                if (rows > 0)   
                {   
                    return rows;   
                }   
                else  
                {   
                    return 0;   
                }   
            }   
            catch  
            {   
                return 0;   
            }   
  
            ////程序解决方案   
            //List<String> list = new List<string>();   
            //list.Add("delete from CHILD_B_J where Id in(" + IdList + ")");   
            //list.Add("delete from CHILD_GUARDIAN where CHILD_B_Id in(" + IdList + ") and StudentType='借读生'");   
            //list.Add("delete from CHILD_REG_J where CHILD_B_Id in(" + IdList + ")");   
            //list.Add("delete from CHILD_Order where CHILD_B_Id in(" + IdList + ") and Child_B_Type='借读生'");   
            //object obj = DbHelperSQL.ExecuteSqlTran(list);   
            //if (obj == null)   
            //{   
            //    return 0;   
            //}   
            //else   
            //{   
            //    return Convert.ToInt32(obj);   
            //}   
        }   

 

ALTER PROCEDURE [dbo].[pro_Child_B_JDel](   
@IdList varchar(250) --主键   
)   
AS   
declare @strSQL1 varchar(200)   
declare @strSQL2 varchar(200)   
declare @strSQL3 varchar(200)   
declare @strSQL4 varchar(200)   
  
BEGIN   
  
     -- Set XACT_ABORT ON;   
  --         Begin  Tran   
        --  delete from CHILD_B_J where Id in(@IdList)   
        --  delete from CHILD_GUARDIAN where CHILD_B_Id in(@IdList) and StudentType='借读生'  
        --  delete from CHILD_REG_J where CHILD_B_Id in(@IdList)   
  
     --Commit Tran   
  
     set @strSQL1='delete from CHILD_B_J where Id in('+@IdList+')'  
     set @strSQL2='delete from CHILD_GUARDIAN where CHILD_B_Id in('+@IdList+') and StudentType='+''''+'借读生'+''''  
     set @strSQL3='delete from CHILD_REG_J where CHILD_B_Id in('+@IdList+')'  
     set @strSQL3='delete from CHILD_Order where CHILD_B_Id in('+@IdList+') and Child_B_Type='+''''+'借读生'+''''  
        
     exec( @strSQL1)   
     exec (@strSQL2)   
     exec( @strSQL3)   
       
END  

 

posted @ 2015-02-05 17:15  奇风★逍遥  阅读(157)  评论(0编辑  收藏  举报