我如何从数据表中清除会话存储的数据 [英] how can i clear session stored data from Data table

查看:51
本文介绍了我如何从数据表中清除会话存储的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发此页面中的网页,我正在下订单并添加多个项目.
在这里,我正在使用一个会话变量来存储这些值,然后显示在数据表中,但是现在我无法计算不同变量的总计,也无法将这些值存储到数据库中.
当我将值存储到数据库时,仅保存了最后一条记录.

我在这里使用两个表
1.product_order
product_id
product_name
product_rate
product_quantity
product_amount

2.product_order详情
product_id
order_id
product_name
product_quantity
product_total

我的代码是

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("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.

推荐答案



您可以像这样计算值:

Hi,

you can calculate value like:

//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"]);
            }




如有任何疑问,请让我知道.

如果对您有帮助,请提供投票.

谢谢,
Imdadhusen




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

Please provide Vote if this would be helpful to you.

Thanks,
Imdadhusen


Session["address"] = null


这篇关于我如何从数据表中清除会话存储的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆