使用会话中的购物车 [英] Shopping cart in using sessions

查看:74
本文介绍了使用会话中的购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我已经使用会话将购物车存储到客户端的会话中.

我将所有购物明细以数据表格式存储.现在我想在数据库中存储相同的数据表,但是我不知道如何将其发送到SQL Server上的存储过程以及如何将其插入数据库中.

我认为可以通过哈希表实现,但是我可以通过哈希表将数据表发送到存储过程吗?如果可以,那么我应该在存储过程中使用哪种数据类型.

有人可以帮我吗?

提前谢谢.
Shailesh J.

hello friends,

I have used sessions to store my shopping cart into sessions at client side.

I am storing all the shopping details in a datatable format. Now i want to store the same datatable in my database but i don''t know how to send it to a stored procedure on SQL server and how to insert the same into database.

I think its possible through hashtable but can i send a datatable to a stored procedure through hash table and if yes then which data type should i take for same in stored procedure.

can anybody help me for same.

Thanks in advance.
Shailesh J.

推荐答案

据我了解...最好的解决方案是BulkCopy
例如:
as i understand ... the best solution is the BulkCopy
ex:
public void BulkCopy()
    {
        dt = (DataTable)Session["lstCars"];
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            SqlCommand cmd = new SqlCommand("TRUNCATE TABLE carsForSale", connection);//this procedure to delete the whole data in  database table 
            connection.Open();
            cmd.ExecuteNonQuery();//first you have to clear the data
            SqlBulkCopy bulkObj = new SqlBulkCopy(connection);//bulkCopy can insert into you dable in database all the values in the DataTable @ the same time
            bulkObj.DestinationTableName = "carsForSale";//table name 
            bulkObj.WriteToServer(dtUsers);//data you want to insert
            connection.Close();
        }
    }


最好的问候


best regards


这篇关于使用会话中的购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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