2010-10-11 52 views
-1

我有一种情况,我需要从表中检索记录并使用这些值并作为存储过程的参数传递。存储过程将重新运行一行,并且我需要使用存储过程返回的值并更新其他表。请给我一个示例C#代码来实现这种情况。任何帮助都将被占用。需要做与SQLServer数据库的多个事务

由于事先

普拉迪普

+3

也只是另一种 “Giv'me泽codez” -Questions ... – 2010-10-11 06:55:51

回答

0

你可以试试这个:

createPROCEDURE MultipleTransaction 

    AS 
    BEGIN 
     -- SET NOCOUNT ON added to prevent extra result sets from 
     -- interfering with SELECT statements. 
     SET NOCOUNT ON; 
     declare @a int; 
     set @a=1; 
     -- Insert statements for procedure here 
     while((select distinct id from a where id [email protected]) is not null) 
     begin 
     declare @name varchar(100) 
     declare @id int 

     set @name =(select distinct name2 from a where id [email protected]) 
     set @id =(select distinct id from a where id [email protected]) 

     exec GetRows @name,@id -- calling another procedure 
     set @a [email protected]+1; 
     end 
    END 


create PROCEDURE GetRows 
    (@Para varchar(100),@id varchar(10) ) 
AS 
BEGIN 
    -- SET NOCOUNT ON added to prevent extra result sets from 
    -- interfering with SELECT statements. 
    SET NOCOUNT ON; 

    -- Insert statements for procedure here 
    UPDATE [Cube].[dbo].[b] 
    SET [name1] = @Para 
WHERE id [email protected] 
END 
+0

我知道这可以实现通过创建新的存储过程,但不幸的是我没有创建任何存储过程的特权,我只需要通过c#代码来实现这一点。 – Pradeep 2010-10-11 07:25:43

+0

在C#代码中这么做很糟糕,因为您正在生成不必要的网络往返。可能是你与那个有权做正确事情的人交谈...... – 2010-10-11 08:02:33

+0

感谢您的回答,但是由于我正在使用使用产品数据的插件,因此无法使用我的方案。我无法创建表格或程序。 – Pradeep 2010-10-11 08:54:08