ASP Tutorial: Write your own database operations

Source: Internet
Author: User
Database operations classes on the Internet a lot, I this is not better than those, just write their own, with more habits. So I have nothing special in this category, just use their habits, as for efficiency, etc., Welcome to enlighten!!

<%
Class Dbclass
'-------------------------------------------------------------------------
' Variable description
' Conn-----------Connection object
' strSQL---------The statement that executes the query
' Vtbname table name--------Query paging
' Vpkey----------The primary key of a table that queries pagination
' vpgfields------Query paging fields to display
' Vpgsize--------The number of records displayed per page of the query page
' Vcurrpg the current page displayed--------query paging
' vconditions----Query paging conditions
' Vorderby-------Query paging sorting
'-------------------------------------------------------------------------
Private Conn,strsql,vtbname,vpkey,vpgfields,vpgsize,vcurrpg,vconditions,vorderby
' Initialization of the class
Private Sub Class_Initialize ()
' Set the following two variables when it is an MS SQL database
The name or IP address of the ' Dim dbserver ' Database Server
Name of the ' Dim dbname ' Database
Dim DBPath ' If an Access database, set its path here
Dim Dbuser ' Login Username for database
Dim dbpass ' Login Password for database
Dim connstr
DBPath = "/testasp/data/data.mdb" Set database path
Dbuser = "Admin"
Dbpass = "123456"
' If you have access, and you have a password
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath (DBPath) &_
"; User id= "& Dbuser &"; password=; Jet oledb:database password= "& Dbpass
' If access, and no password
' ConnStr = ' Provider = microsoft.jet.oledb.4.0;data Source = ' & Server.MapPath (DBPath)
' If the Ms-sql database
' ConnStr = ' Provider = SQLOLEDB; User ID = "& Dbuser &"; Password = "& Dbpass &_
' "; Initial Catalog = "& dbname &"; Data Source = "& DBServer
On Error Resume Next
Set Conn=server. CreateObject ("Adodb.connection")
Conn.Open ConnStr
ErrMsg "Connection Database"
End Sub
' Class end
Private Sub Class_Terminate ()
Conn.close
Set conn=nothing
End Sub
'-------------------------------------------------------------------------
' Set the value of the variable for the class
'-------------------------------------------------------------------------
' Set up SQL statements
Public Property Let Sqlstr (Byval Values)
Strsql=values
End Property
' Set table name for query paging
Public Property Let Tbname (Byval Values)
Vtbname=values
End Property
'--------------------------------------------------------
' Set the primary key for a table that queries pagination
Public Property Let Pkey (ByVal Values)
Vpkey=values
End Property
'--------------------------------------------------------
' Set the fields displayed
Public Property Let Pgfields (ByVal Values)
Vpgfields=values
End Property
'--------------------------------------------------------
' Set the number of records to display per page
Public Property Let Pgsize (ByVal Values)
Vpgsize=values
End Property
'---------------------------------------------------------


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.