Hi,
I am using three tables
1.order
customer_name nvarchar(20)
customer_phone intcustomer_address nvarchar(50)
order_id int pk
product_id int fk
product_total_amount int
2.product
Product_Name nvarchar(20)
Product_Quantity int
Product_Id int pk
Product_Rate int
3.order details
orderdeatilsID int
order_id int
product_id int
product_quantity int
product_amount int
and stored procedure is:
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:
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.