这是相关的代码:
if (Session["UserID"] != null)
{
//向购物车中添加商品,如果购物车中已经存在该商品,则商品数量加1,如果是第一次购买,则向购物车中添加一条商品信息
string P_str_CartID = Session["UserID"].ToString();
string P_str_FoodID = Request["FoodID"];
DataSet ds = DB.reDs("select count(*) from tb_Cart where CartID=" + P_str_CartID + "and FoodID=" + P_str_FoodID);
if (ds.Tables[0].Rows[0][0].ToString() == "0")
{
DataSet ds1 = DB.reDs("select FoodName,FoodPrice from tb_Food where FoodID=" + P_str_FoodID);
string P_str_FoodName = ds1.Tables[0].Rows[0][0].ToString();
string P_str_FoodPrice = ds1.Tables[0].Rows[0][0].ToString();
string P_str_Num = "1";
DB.ExSql("insert into tb_Cart values(" + P_str_CartID + "," + P_str_FoodID + ",'" + P_str_FoodName + "'," + P_str_FoodPrice + "," + P_str_Num + ")");
}
else
{
DB.ExSql("update tb_Cart set Num=Num+1 where CartID=" + P_str_CartID + "and FoodID=" + P_str_FoodID);
}
}
else
{
Response.Write("<script>alert('您还没有登录,请先登录再购买!');</script>");
}
Bind();
//显示购物车中的商品信息 }