控制来自C#的循环并插入存储过程中的临时表 [英] controlling a loop from C# and insert into a temp table in a stored procedure

查看:172
本文介绍了控制来自C#的循环并插入存储过程中的临时表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的专家,



请提供一个示例循环和ASP.NET中的代码,C#。



或更好的执行以下例程的参考站点:





循环的控制是 C#, asp,net



但生成数据的插入是在存储过程中完成的







如果有10条记录可供使用。



循环的控制来自asp,net程序。



在每个进程之后,输出被发送到存储过程。

Dear expert,

please provide a sample loop and codes that is in ASP.NET, C#.

or better a reference site that performs the following routine :


The control of the loop is C#, asp,net

but the insert of the generated data is done in the stored procedure



If there are 10 records to be worked .

The control of the loop is from the asp,net program.

After each process the output is sent to a stored procedure.

推荐答案

您可以将数据作为表传递..

,您可以使用UDT(用户自定义表类型)

这是创建UDT的代码



You can pass the data as a table..
for that you can use UDTs (User Defined Table Types)
this is the code for creating a UDT

CREATE TYPE [dbo].[ttAddressType] AS TABLE(
    [addressTypeID] [int] NULL,
    [addressType] [nvarchar](500) NOT NULL
)
GO





您可以在存储过程中使用它,例如



You can use this in your stored procedure like

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      Jineesh
-- Create date: 29-11-2012
-- Description:	
-- =============================================
ALTER PROCEDURE [dbo].[spAddressType]
(@addressType ttAddressType READONLY)

AS
BEGIN
	SET NOCOUNT ON;
	SET XACT_ABORT ON;
	
	BEGIN TRY
		BEGIN TRAN

--code for inserting in to table

              COMMIT TRAN
       END TRY
END






请提供一些你尝试过的代码..



无论如何,你可以使用foreach或for循环你的C#代码。并且你可以将所有行传递给存储过程,从那里你可以将它移动到临时表。



请检查
Hi,

Please provide some code you have tried..

anyway, you can use foreach or for loop in your C# code. and you can pass all the rows to a stored procedure, from there you can move it to a temporary table.

Please check


这篇关于控制来自C#的循环并插入存储过程中的临时表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆