Share via


Code to Search for an Order and Display Line Item Information

After an order has been saved to the database, you can search for it based on a variety of criteria. In this example, the OrderGroupID will serve as the basis for the search.

This example code requires that you have already saved the order to the database as a template as is described in Code to Save an Order to the Database. Note that in the following example, the connection strings have been formatted for better display.

  1. Create and initialize the OrderGroup object.

    Dim oOrderGroup
    Set oOrderGroup = Server.CreateObject("Commerce.OrderGroup")
    oOrderGroup.Initialize "Provider=SQLOLEDB.1;User ID=sa;Password=;
                                 Initial Catalog=""Retail_commerce"";
                                                DataSource=TESTMACH2;
                                           Network Library=dbmssocn",
                                                              sUserID
    
  2. Create the SimpleFindSearchInfo object and set it to search for a known OrderGroupID.

    Dim oSFSearch, sReqID
    Set oSFSearch = Server.CreateObject("Commerce.SimpleFindSearchInfo")
    sReqID ="754C40C6-EAA9-454C-A8AB-02789FBE0FB9"
    oSFSearch.ordergroup_id = sReqID
    
  3. Create the SimpleFindResultInfo object and set it to return data from the OrderGroup, OrderFormHeader, and OrderFormLineItems tables. Setting the JoinLineItemInfo property to True will cause the returned result set to include data from the OrderFormLineItems table. Setting the JoinOrderFormInfo property to True will cause the returned result set to include data from the OrderFormHeader table.

    Dim oSFResult
    Set osfResult =Server.CreateObject("Commerce.SimpleFindResultInfo")
    oSFResult.JoinLineItemInfo = True
    oSFResult.JoinOrderFormInfo = True
    
  4. Create a recordset to hold the search results.

    Dim oRSResults
    Set oRSResults=Server.CreateObject("ADODB.Recordset")
    
  5. Execute the search using the OrderGroupManager.SimpleFind method. The parameters for this method are the SimpleFindSearchInfo and SimpleFindResultInfo objects. Write the success status of the search to the screen.

    Set oRSResults= oOGMgr.SimpleFind(oSFSearch, oSFResult)
    If err.number <> 0 Then
        Response.Write "Search error"
    Else
        Response.Write "Successful Search" & "<br>"
    End If
    
  6. Iterate through the recordset, writing the OrderGroupID and the quantity ordered for each line item to the screen.

    While Not oRSResults.EOF
        vtDisplay = "OrderGroup ID = " & oRSResults("ordergroup_id") _
                    & "<br>"
        Response.Write vtDisplay
        vtDisplay = "Quantity = " & oRSResults("quantity") _
                    & "<br>" & "<br>"
        Response.Write vtDisplay
        oRSResults.MoveNext
    WEnd
    


All rights reserved.