Source Code for http://194.8.136.100/XSB/bagxml.asp

COLOR LEGEND
Server Side Script
Client Side Script
Hyperlink
Include
Frames
Comments
Object Code Link
Standard HTML and Text


<%
' check if product is valid and not made up
nProductId = Trim(Request.QueryString("id"))
bValid = True

If "" = nProductId Or Not IsNumeric(nProductId) Then
   bValid = False
Else
   Set objConn = Server.CreateObject("ADODB.Connection")
   objConn.Open "provider=sqloledb.1;user id=sa;password=;" & _
     "initial catalog=Northwind;data source=TOPGUN"
   Set objRS = Server.CreateObject("ADODB.Recordset")
   Set objRS.ActiveConnection = objConn
   objRS.Open "SELECT ProductID, ProductName, QuantityPerUnit, " & _
       "UnitPrice FROM Products WHERE ProductId=" & nProductId
   If objRS.EOF And objRS.BOF Then
     bValid = False
   Else
     avarProduct = objRS.GetRows()
   End If
   objConn.Close
   Set objRS = Nothing
   Set objConn = Nothing
End If

' get or create the shopping bag
Set myBag = Server.CreateObject("SoftwingXSB.ShoppingBag")
If Not IsEmpty(Session("BagItems")) Then
   myBag.LoadBag CStr(Session("BagItems"))
Else
   myBag.InitBag
End If

' if the product was ok, add it to the bag
If bValid Then
   ' first check if the product isn't already in the bag
   If Not myBag.IsProductInBag(nProductId) Then
     myBag.LineItems.AddLineItem avarProduct(0,0), Server.HtmlEncode(avarProduct(1,0)), _
       Server.HtmlEncode(avarProduct(2,0)), avarProduct(3,0), 1
   End If
End If

Session("BagItems") = myBag.SaveBag

Response.Write "<?xml version=""1.0""?>"
Response.Write Session("BagItems")
%>