将数据插入两个表..
问题描述:
先生在我的应用程序中我有2个表,主表和详细信息表..文本框值插入主表和网格视图数据插入详细信息表..
使用存储过程如何在单个过程中插入两个数据。帮助先生
Sir in my application i have 2 tables , Master table & Detail table.. Text box values are insert into master table & grid view data insert into Detail table..
Using store procedure how to insert both data in single procedure . help sir
答
你可以编写一个程序
You can write a single procedure
USE [YourDatabase]
GO
/****** Object: StoredProcedure [dbo].[SP_Fr_FileUpDate] Script Date: 02/10/2014 09:00:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create procedure [dbo].[SP_Fr_FileUpDate]
@param1 varchar(MAX),
@param2 int,
@param3 Date
as
Begin
Insert Query
Insert Query
END
end
Crate a SP
Crate an SP
ECLARE @NewID INT
INSERT INTO Table1(A,B,C......) VALUES(a,b,c, .....)
SELECT @NewID = SCOPE_IDENTITY()
INSERT INTO Table2(A,B,C...) VALUES(@NewID, B,..........)
begin transaction
insert query for first table
insert query for second table
Rollback transaction