网络编程
位置:首页>> 网络编程>> Asp编程>> asp网上购物车实例代码(3)

asp网上购物车实例代码(3)

  发布时间:2007-10-03 13:43:00 

标签:购物车

六、 UpdateCart.asp
   接收AddtoCart.asp传递来的prodID、prodName、prodPrice和OrderQty,加上客户的Session编号,存入Cart表中。
  1、 添加记录集cartRec,设置数据源为Select * From Cart
  2、 添加更新数据的代码:


<Script Language=Javascript Runat=Server>
function cartRec_onbeforeopen(){
if(Request("InCart")==0) 
{
newSQL="Select * From Cart";
}//不在购物车中,取出所有数据
else 
{
newSQL="Select * From Cart Where SessionID="+Session.SessionID;
}//已经在购物车中,取出唯一的数据,准备修改数据
cartRec.setSQLText(newSQL);
}
function cartRec_ondatasetcomplete(){
if(Request("InCart")==0) //如果不在购物车中,添加新纪录
{
fields=new Array("ProductID","ProductName"Quantity","SessionID");
values=new Array(Request("prodID"),Request("prodName"),Request("OrderQty"),Session.SessionID);
cartRec.AddImmeidate(fields,values);
}
else//如果已经在购物车中,更新购买数量
{
cartRec.fields.setValue("Quantity",Request("OrderQty"));
}
Response.Redirect("ViewCart.asp");
</Script>


0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com