Hi,
I am developing a web page in this page i am placing a order with more then one items.
here i am using a session variable to store these value and then display in datatable but now i am unable to calculation of total for different variable and unable to store these value to database.
when i storing value to database only last record saved.
Here i am using two tables
1.product_order
product_id
product_name
product_rate
product_quantity
product_amount
2.product_order detail
product_id
order_id
product_name
product_quantity
product_total
my code is
protected void Createdatatable()
{
DataTable dt = new DataTable();
dt.Columns.Add("Product_Name");
dt.Columns.Add("Product_Quantity");
dt.Columns.Add("Product_Amount");
Session["address"] = dt;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
double a, b;
a = double.Parse(txtqty.Text);
b = a * double.Parse(LblRate1.Text);
txtAmount.Text = b.ToString();
dt = (DataTable)Session["Address"];
dr = dt.NewRow();
dr["Product_Name"] = DropDownList1.SelectedItem.Text;
dr["Product_Quantity"] = txtqty.Text;
dr["product_rate"] = LblRate1.Text;
dr["Product_Amount"] = txtAmount.Text;
dt.Rows.Add(dr);
dt.AcceptChanges();
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.Visible = true;
}
<pre lang="cs">}
protected void btnSubmit_Click(object sender, EventArgs e)
{
grandtotal();
try
{
con.Open();
cmd = new SqlCommand("insert into product_customer(customer_name,customer_phone,customer_address)values(@customer_name,@customer_phone,@customer_address)", con);
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.ExecuteNonQuery();
cmd = new SqlCommand("insert into product_order(product_name,product_quantity,product_amount,product_total_amount)values(@product_name,@product_quantity,@product_amount,@product_total_amount)", con);
cmd.Parameters.Add("@product_name", SqlDbType.NVarChar).Value = DropDownList1.SelectedItem.Text;
cmd.Parameters.Add("@product_quantity", SqlDbType.NVarChar).Value = txtqty.Text;
cmd.Parameters.Add("@product_amount", SqlDbType.NVarChar).Value = txtAmount.Text.ToString();
cmd.Parameters.Add("@product_total_amount", SqlDbType.NVarChar).Value = txtTotalAmount.Text.ToString();
cmd.ExecuteNonQuery();
cmd.Dispose();
}
what is the way to store all inserted value in database.
and how we make clear clear data table.