Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 9-Feb-14 20:57pm
v2

You can write a single procedure

SQL
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
 
Share this answer
 
Comments
Ajith.Kerala 10-Feb-14 5:41am    
Grid view data is insert into the second table .. how can i pass all the row wise data into this procedure..
Crate an SP


SQL
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,..........)
 
Share this answer
 
SQL
begin transaction


insert query for first table 

insert query for second table
Rollback transaction
 
Share this answer
 
try like this
SQL
Create PROCEDURE [dbo].[sp_InsertinTwoTables]
   @param1 varchar(MAX),
	@param2 varchar(20),
	@param3 varchar(10)


as
BEGIN
BEGIN TRY --Starts the Try Block..
BEGIN TRANSACTION -- transaction..starts

	Insert into table1 (col1,col2,col3) values (@param1,@param2,@param3)
	
	Insert into table2 (col1,col2,col3) values (@param1,@param2,@param3)

COMMIT TRAN -- Success!
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK TRAN --RollBack in case of Error
END CATCH
END
 
Share this answer
 
Comments
Ajith.Kerala 10-Feb-14 5:42am    
am trying to insert grid view data into table 2.. then can it possible ?
[no name] 10-Feb-14 5:54am    
Why not you can do it.
OPees 10-Feb-14 5:49am    
yes just comment 1st insert statement

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900