string strSql = " DECLARE @userID int ";
strSql+=" set @userID="+userID.ToString();
strSql+=" DELETE FROM Accounts_RolePermissions WHERE userID=@userID";
strSql+=" DELETE FROM com_info WHERE comID=@userID ";strSql+=" declare @i int,@s bigint set @i=1";
strSql+=" while(@i=1) ";
strSql+="   begin ";
strSql+="   select @s=max(jobID) ";
strSql+="   from com_job";
strSql+="   where userID=@userID";
strSql+="   if(@s is null)  begin  set @i=0   end  ";
strSql+="   else begin";
strSql+=" DELETE FROM person_Job_Collection WHERE JobCollection_jobID =@s ";strSql+=" DELETE FROM com_job WHERE jobID = @s ";
strSql+=" set @s=null end end";strSql+=" DELETE FROM com_job WHERE userID=@userID";
下面的怎么写?
SqlConnection MyConn = new SqlConnection(ConnectionString);SqlCommand myComm = new SqlCommand(strSql,MyConn);我试了用SqlCommand和SqlDataAdapter都不行
望高手指点!!
说明不用存储过程,用的话很好解决。

解决方案 »

  1.   

    那我在给你们补充一下,
    MyConn.Open();
    myComm.ExecuteNonQuery();
    MyConn.Close();
    --------------------------------------------
    SqlDataAdapter MyAdapter = new SqlDataAdapter(strSql,MyConn); DataSet objDS = new DataSet();MyAdapter.Fill(objDS);
    -=---------------------------------
    这都不行?我试了都不行
      

  2.   

    改成
    string strSql = "exec(' DECLARE @userID int ";
    strSql+=" set @userID="+userID.ToString();
    strSql+=" DELETE FROM Accounts_RolePermissions WHERE userID=@userID";
    strSql+=" DELETE FROM com_info WHERE comID=@userID ";strSql+=" declare @i int,@s bigint set @i=1";
    strSql+=" while(@i=1) ";
    strSql+="   begin ";
    strSql+="   select @s=max(jobID) ";
    strSql+="   from com_job";
    strSql+="   where userID=@userID";
    strSql+="   if(@s is null)  begin  set @i=0   end  ";
    strSql+="   else begin";
    strSql+=" DELETE FROM person_Job_Collection WHERE JobCollection_jobID =@s ";strSql+=" DELETE FROM com_job WHERE jobID = @s ";
    strSql+=" set @s=null end end";strSql+=" DELETE FROM com_job WHERE userID=@userID')";试一下
      

  3.   

    刚错了,userID.ToString()应该作为参数传递
      

  4.   

    在执行strSql+=" set @userID="+userID.ToString();这句的时候,如果userID能获取到值得话就不用写成参数了。我也是根据存储过程来看的。
      

  5.   

    不会的。string strSql = "exec(' DECLARE @userID int ";在Sql中exec就是执行语句的命令。你原来定义的strSql可能没有执行