Use only one session to solve the shopping cart (2)

Source: Internet
Author: User
Tags vbscript class access database
session| Shopping Cart | I'm going to include all the programs I've used in a VBScript class. It consists of 3 functions: AddItem (), DeleteItem () and DeleteAll (), and a public process: Displaycart (). The first two functions additem () and DeleteItem () have only one parameter, which is the item to be added or deleted, which can be a commodity name (a string) or a product ID number corresponding to the database. The purpose of the DeleteAll () function is to empty the shopping cart. The parameter of the procedure Displaycart () can be "list" or "option", which determines whether to display the cart information in the form of a list or a drop-down box.

This VBScript class also includes two private functions Readfromdb () and Regexpitem () for AddItem () and DeleteItem () calls.

It is more convenient to use the commodity ID number than the product name, so we use the commodity ID number as the parameter in the AddItem () or DeleteItem () function, in which we pass the ID number to the Readfromdb () function, by Readfromdb () function to read the product name from the database. Since Readfromdb () is not intended to be invoked in other functions, we declare readfromdb () as a private function. Similarly, the following Regexpitem () is also a private function.

The Readfromdb () function

Now let's look at the Readfromdb () function:


Private Function Readfromdb (Argitem)
Dim objconn, objRS
Dim strSQL

Strsql= "SELECT ProductName from tblproducts WHERE productid=" &argitem

Set Objconn=server.createobject ("Adodb.connection")
objConn.Open "File name=d:\inetpub\wwwroot\shoppingcarts\shoppingcarts.udl"

Set Objrs=objconn.execute (strSQL)
Readfromdb=objrs ("ProductName")

Objrs.close
Set objrs=nothing
Objconn.close
Set objconn=nothing

End Function


This function first establishes a database connection, then reads the database, and finally returns the name of the commodity corresponding to the parameter (commodity ID number). This article comes with an Access database containing 10 items for your reference.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.