Previous in Contents Next in Contents

DBStorage Object Overview

The DBStorage object is created as needed on each page. Use the Active Server Pages (ASP) Server object's CreateObject method to create a DBStorage object, as follows:

Set mscsOrderFormStorage = Server.CreateObject("Commerce.DBStorage")

This function call returns an uninitialized instance of a DBStorage object. Use the InitStorage method to initialize the returned object instance. Attempting to call any other DBStorage method prior to calling InitStorage results in an error.

The DBStorage object serves as an interface between the site database and Dictionary, SimpleList, and OrderForm objects. A DBStorage object contains methods for transferring data between the database and the data object.

For information about the relationships between the OrderForm object, the DBStorage object, and the site database, see "The Order Form Table and the DBStorage Object" in Architecture of a Business-to-Consumer Site in the Commerce documentation.

When the DBStorage object retrieves data from the database, it creates the appropriate type of data object (an OrderForm or Dictionary), stores the requested data into the object, and returns the data object. When the DBStorage object is used to save data in the database, you pass it the OrderForm or Dictionary object containing the data, and the DBStorage method copies the data from the data object into the database.

The following example is from the Clocktower's Basket.asp file. This code creates a DBStorage object, assigning it the name mscsOrderFormStorage. It then invokes the object's InitStorage method to establish a link to the data source and to identify the type of object to be read or written as an OrderForm object. Next, the DBStorage object's GetData method is called to retrieve OrderForm data corresponding to the current shopper ID. If no such data already exists, the GetData method returns Null; in that case, the application creates and initializes a new OrderForm object. Otherwise, the OrderForm object is used to process and display the items in the customer's basket:

REM -- Create a storage object for the order forms (shopper's basket)
Set mscsOrderFormStorage = Server.CreateObject("Commerce.DBStorage")
Call mscsOrderFormStorage.InitStorage(MSCSSite.DefaultConnectionString, "Clocktower_basket", "shopper_id", "Commerce.OrderForm", "marshalled_order", "date_changed")

on error resume next
set mscsOrderForm = mscsOrderFormStorage.GetData(null, ShopperID)
on error goto 0
if IsNull(mscsOrderForm) then
    Set mscsOrderForm = Server.CreateObject("Commerce.OrderForm")
    orderFormItems = null
    nOrderFormItems = 0
else
REM ( load and run pipeline)
end if

Note  The DBStorage object's CommitData method does not support tables containing fields of type TimeStamp. Instead, use the DateChanged argument to the DBStorage.InitStorage method, which provides the same functionality as using TimeStamp fields.




© 1997-2000 Microsoft Corporation. All rights reserved.