Click here to Skip to main content
15,896,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi,

I am using three tables
1.order
SQL
customer_name	nvarchar(20)	
customer_phone	intcustomer_address nvarchar(50)	
order_id	  int	pk
product_id	  int	fk
product_total_amount int

2.product
SQL
Product_Name	nvarchar(20)	
Product_Quantity	int	
Product_Id	int	pk
Product_Rate	int

3.order details
SQL
orderdeatilsID	int	
order_id	int	
product_id	int	
product_quantity   int	
product_amount	int

and stored procedure is:
SQL
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[insert_order]
(@customer_name nvarchar(20),
@customer_address nvarchar(50),
@customer_phone nvarchar(10),
@product_quantity nvarchar(5),
@product_amount nvarchar(5),
@product_total_amount nvarchar(5))
AS
BEGIN
SET NOCOUNT ON;
declare @test int
insert into product_order(customer_name,customer_phone,customer_address,,product_total_amount)value(@customer_name,@customer_phone,@customer_address,,@product_total_amount)

set @test=scope_identity()
insert into product_order_details(product_quantity,product_amount,order_id)values
(@product_quantity,@product_amount,@test)	
END

My code is:
C#
protected void btnSubmit_Click(object sender, EventArgs e)
       {
          grandtotal();

           try
           {
               con.Open();
               cmd = new SqlCommand("insert_ordr", con);
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.Add("@customer_name", SqlDbType.NVarChar).Value = txtName.Text;
               cmd.Parameters.Add("@customer_phone", SqlDbType.NVarChar).Value = TxtPhone.Text;
               cmd.Parameters.Add("@customer_address", SqlDbType.NVarChar).Value = txtAddress.Text;
               cmd.Parameters.Add("@product_total_amount",
 SqlDbType.Int).Value = txtTotalAmount.Text.ToString();
             
               cmd.Parameters.Add("@product_quantity", SqlDbType.Int).Value = txtqty.Text.ToString();
               cmd.Parameters.Add("@product_amount", SqlDbType.Int).Value = txtAmount.Text.ToString();

cmd.ExecuteNonQuery();


               cmd.Dispose();
           }

           catch (Exception exe)
           {

               Response.Write(exe);
           }
           con.Close();
           Session["address"] = null;

       }

I am placing order but saving only last record and from order list.
here i want that when i place order only one order_id should be generate and orderdeatilsID generate for all item and productid also should be update in order table.
Posted
Updated 22-Sep-10 6:36am
v2
Comments
Corporal Agarn 23-Sep-10 14:32pm    
Is the submit button passing one record at a time? Seems to be how it is written???

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