Click here to Skip to main content
15,907,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends

i have one query related to store procedure :

i have 2 table named 1) OrderMaster 2) OrderProduct

here is detail of both table :
OrderMaser :-
SQL
ID	int	Unchecked
OrderID	int	Unchecked
OrderDate	datetime	Checked
StoreID	int	Unchecked
CheckoutType	int	Checked
ShippingAddress	varchar(1000)	Unchecked
ZoneID	int	Unchecked
StateID	int	Unchecked
CityID	int	Unchecked
PinCode	int	Unchecked
ContactNo	int	Checked
EmailID	varchar(100)	Checked
OrderStatus	varchar(50)	Checked
Comments	varchar(1000)	Checked
IsDeleted	bit	Unchecked


2)OrderProduct :-
SQL
ID	int	Unchecked
OrderID	int	Checked
ProductName	varchar(500)	Checked
Quantity	int	Checked
Price	float	Checked



Now i want to when i create a order data will insert in OrderMaster table. Also add the OrderProduct table but there is multiple product in that table. there is OrderID have unique key in OrderMaster Table and Forienkey in OrderProduct Table.

how can i solve that ....!!!

Thank To All in Advance,
Posted

You can pass a datatable to your stored procedure. Then you can add as many rows as you like in one go.

Here's an article explaining how :
Passing an array or DataTable into a stored procedure[^]
 
Share this answer
 
I guess you will be passing ProductName, Quantity and PRICE also when creating an order.

So have a stored proc with input parameters for all the columns


@OrderID
@OrderDate
@StoreID
@CheckoutType
@ShippingAddress
@ZoneID
@StateID
@CityID
@PinCode
@ContactNo
@EmailID
@OrderStatus
@Comments
@IsDeleted
@ProductName
@Quantity
@Price

Then insert into orderMaster

like

SQL
insert into ordermaster values (
@OrderID,	
@OrderDate,
@StoreID,
@CheckoutType,
@ShippingAddress,
@ZoneID,
@StateID,	
@CityID,
@PinCode,
@ContactNo,
@EmailID,
@OrderStatus,
@Comments,
@IsDeleted)


then insert into orderproduct
SQL
insert into orderproduct values (@orderid,@ProductName,@Quantity,@Price	)


This is not complete stored proc. I have explained the logic to insert. You have to write from this.
 
Share this answer
 
Comments
Yatin chauhan 17-Aug-12 3:39am    
oky sir but how can it allows multiple product insert in OrderProduct table. when i insert a recorde in OrderMaster table then i have to declare an OrderID = SCOPE_IDENTITY() like that.

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