Click here to Skip to main content
15,917,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
protected void Createdatatable()
{
 DataTable dt = new DataTable();
 //dt.Columns.Add("Id");
 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.
Posted
Updated 20-Sep-10 23:43pm
v4
Comments
m@dhu 21-Sep-10 1:33am    
update your code with pre tags..

Hi,

you can calculate value like:

C#
//Now you can convert Session object to DataTable to retrive values.
            DataTable dtRetrived = (DataTable)Session["address"];
            //Iterate each row with value
            int Total = 0;
            for (int r = 0; r < dtRetrived.Rows.Count; r++)
            {
                //Calculate total value
                Total += Convert.ToInt32(dtRetrived.Rows[r]["roduct_Quantity"]) * Convert.ToInt32(dtRetrived.Rows[r]["Product_Amount"]);
            }



Please do let me know, if you have any doubt.

Please provide Vote if this would be helpful to you.

Thanks,
Imdadhusen
 
Share this answer
 
Comments
call to .net 21-Sep-10 1:59am    
thanks buddy it is working.
Session["address"] = null
 
Share this answer
 
Comments
call to .net 21-Sep-10 6:34am    
it is not wrking bro.

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