Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two table
1. sell_master, fields are in_sell_id(identity),mn_sell_amount

2. sell_detail, fields are in_sell_id(not identity),vc_item_name

from aspx page i am inserting record in above mentioned table, When i click on submit button one record should inserted in sell_master and record corrusponding recent generated id should inserted in sell_detail table.

For ex :

sell_master
--------------
in_sell_id mn_sell_amount

1 500

2 800


sell_detail
--------------------
in_sell_id vc_item_name

1 juice
1 sweets
2 paneer
2 chicken


How can i do same as above ?
Posted
Comments
Herman<T>.Instance 10-Sep-12 8:21am    
use db triggers

1 solution

You can use SCOPE_IDENTITY[^] to get the recent generated Id. Here is a sample approach

SQL
INSERT INTO sell_master ( mn_sell_amount) VALUES (500)

DECLARE @in_sell_id INT
SET @in_sell_id = SCOPE_IDENTITY()

INSERT INTO sell_detail(in_sell_id, vc_item_name) VALUES (@in_sell_id,'juice')
INSERT INTO sell_detail(in_sell_id, vc_item_name) VALUES (@in_sell_id,'sweets')
 
Share this answer
 

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