ASP.NET+SQL2005实现购物车相同商品的数据叠加
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class gwc : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (Session["temp"] == null) { Random rnd = new Random(); int n = rnd.Next(1000, 9999); string newname = DateTime.Now.Year.ToString().Trim() + DateTime.Now.Month.ToString().Trim() + DateTime.Now.Day.ToString().Trim() + DateTime.Now.Hour.ToString().Trim() + DateTime.Now.Minute.ToString().Trim() + DateTime.Now.Second.ToString().Trim() + n.ToString().Trim(); Session["temp"] = newname; } if (!IsPostBack) { string sql; sql = "select * from goumaijilu where goumairen ='" + Session["temp"].ToString().Trim() + "' order by id desc"; getdata(sql); } } private void getdata(string sql) { DataSet result = new DataSet(); result = new Class1().hsggetdata(sql); if (result != null) { if (result.Tables[0].Rows.Count > 0) { DataGrid1.DataSource = result.Tables[0]; DataGrid1.DataBind(); Label1.Text = "以上数据中共" + result.Tables[0].Rows.Count + "条"; } else { DataGrid1.DataSource = null; DataGrid1.DataBind(); Label1.Text = "暂无任何数据"; } } } protected void Button1_Click(object sender, EventArgs e) { string sql; sql = "select * from goumaijilu where goumairen ='" + Session["temp"].ToString().Trim() + "'"; if (bianhao.Text.ToString().Trim() != "") { sql = sql + " and bianhao like '%" + bianhao.Text.ToString().Trim() + "%'"; } if (mingcheng.Text.ToString().Trim() != "") { sql = sql + " and mingcheng like '%" + mingcheng.Text.ToString().Trim() + "%'"; } sql = sql + " order by id desc"; getdata(sql); } protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e) { string sql; sql = "select * from goumaijilu where goumairen ='" + Session["temp"].ToString().Trim() + "' order by id desc"; getdata(sql); DataGrid1.CurrentPageIndex = e.NewPageIndex; DataGrid1.DataBind(); } public string riqigeshi(object str) { string strTmp = str.ToString(); DateTime dt = Convert.ToDateTime(strTmp); string ss = dt.ToShortDateString(); return ss; }}
[解决办法]
问题出在,你购物车,里面,没有匹配,是那个用户购买的字段,添加这个一个字段,匹配会员表用户名,添加的时候,查询购物车表,匹配对于的购物信息。
[解决办法]
数量添加价格跟着变?
[解决办法]
那显示的时候就按照一些信心去找啊,找到的数据,如果相同就group by 字段,显示一个总的数量,或者就同种商品有几条记录就显示几条,这样呢也行的。
[解决办法]
往购物车添加商品时,根据购买人和商品的编号或名称查找该用户购物车是否已存在该商品,存在则数量累计,不存在则添加新数据。页面显示局部刷新下就可以了。
[解决办法]
问题出在,你购物车,里面,没有匹配,是那个用户购买的字段,添加这个一个字段,匹配会员表用户名,添加的时候,查询购物车表,匹配对于的购物信息。