首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

,小弟我的购物车只能有一条记录,

2012-09-03 
在线等,我的购物车只能有一条记录,急!!!!C# codeusing Systemusing System.Datausing System.Configurat

在线等,我的购物车只能有一条记录,急!!!!

C# code
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;using System.Text;using System.Data.SqlClient;public partial class ShoppingCart : System.Web.UI.Page{    public int goods_id = 0;    public int ProdCount = 0;    public int sum = 0;    DataSet ds = new DataSet();            protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            HttpCookie cookie = Request.Cookies["UserInfo"];            if (null == cookie)            {                Response.Write("<script>location.href='login.aspx'</script>");                Response.End();            }            if (Request.QueryString["goods_id"] != null || Request.QueryString["goods_id"] != "")            {                goods_id = Convert.ToInt32(Request.QueryString["goods_id"]);            }            if (Request.QueryString["ProdCount"] != null || Request.QueryString["ProdCount"] != "")            {                ProdCount = Convert.ToInt32(Request.QueryString["ProdCount"]);            }            DataTable newDT = new DataTable("CartTable");            ds.Tables.Add(newDT);            DataColumn newDC;            newDC = new DataColumn("ProdID", System.Type.GetType("System.Int32"));            ds.Tables["CartTable"].Columns.Add(newDC);            newDC = new DataColumn("ProdCount", System.Type.GetType("System.Int32"));            newDC.DefaultValue = 2;            ds.Tables["CartTable"].Columns.Add(newDC);            newDC = new DataColumn("ProName", System.Type.GetType("System.String"));            ds.Tables["CartTable"].Columns.Add(newDC);            newDC = new DataColumn("SalePrice", System.Type.GetType("System.Double"));            ds.Tables["CartTable"].Columns.Add(newDC);            newDC = new DataColumn("MarketPrice", System.Type.GetType("System.Double"));            ds.Tables["CartTable"].Columns.Add(newDC);            Session["myCartTable"] = ds;            StringBuilder strSqlString = new StringBuilder();            strSqlString.Append("select ");            strSqlString.Append("pro_name, ");            strSqlString.Append("pro_sale_price, ");            strSqlString.Append("pro_market_price ");            strSqlString.Append("from ");            strSqlString.Append("tb_products ");            strSqlString.Append("where ");            strSqlString.Append("pro_id = " + goods_id);            DataSet dss = SqlHelper.GetDataSet(SqlHelper.ConnectionString, CommandType.Text, strSqlString.ToString(), null);            if (goods_id > 0)            {                if (dss.Tables[0].Rows.Count > 0)                {                    DataRow dr = newDT.NewRow();                    dr["ProdID"] = goods_id;                    dr["ProdCount"] = ProdCount;                    dr["ProName"] = dss.Tables[0].Rows[0]["pro_name"];                    dr["SalePrice"] = dss.Tables[0].Rows[0]["pro_sale_price"];                    dr["MarketPrice"] = Convert.ToDouble(dss.Tables[0].Rows[0]["pro_sale_price"]) * ProdCount;                    newDT.Rows.Add(dr);                }            }            if (ds.Tables[0].Rows.Count > 0)            {                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)                {                    sum += Convert.ToInt32(ds.Tables[0].Rows[i]["MarketPrice"]);                }                RepM.DataSource = ds;                RepM.DataBind();            }        }    }} 



[解决办法]
http://blog.csdn.net/happy664618843/archive/2010/12/02/6049849.aspx参考

热点排行