Class for running SQL statements on a specified database

Source: Internet
Author: User
'Class for running SQL statements on the specified database
'Dim runs
'Set runs = new runsql
'Runs. setdbn = database name
'If runs. ifok then
'Response. write runs. errs
'Response. end
'End if
'Runs. setsql = SQL
'Runs. run
'If runs. ifok then
'Response. write runs. errs
'Response. end
'Response. write "execution successful"
'End if
On error resume next
Class runsql
Private dbname' database name
Private SQL 'SQL statement to be executed
Private ifsure 'is used to save the success flag. If the success value is false, the failure value is true, and the initial value is true.
Private errstr 'Save the incorrect description text
'Get the ifsure value
Property get ifok ()
Ifok = ifsure
End property
'Get errstr value
Property get errs ()
Errs = errstr
End property
Private sub class_initialize ()
'Set the initial values of ifsure and errstr
Ifsure = true
Errstr = "execute SQL statements on the pointing database"
End sub
'Assign a value to dbname
Property let setdbn (dbn)
Dbname = dbn
Ifexistdb dbn
End property
'Assign a value to SQL
Property let setsql (s)
SQL = s
End property
'Execute the operation
Public sub run ()
'Restore class status
'Check whether the parameters are complete
If isnull (dbname) or isempty (dbname) or cstr (dbname) = "" then
Errstr = "dbname cannot be blank"
Exit sub
End if
If isnull (SQL) or isempty (SQL) or cstr (SQL) = "" then
Errstr = "SQL cannot be blank"
Exit sub
End if
Dim Conn' connection database object
Set conn = Server. CreateObject ("adodb. connection ")
If err. number <> 0 then
Errstr = "an error occurred while establishing the adodb. connection object ."
Set objcreate = nothing
Exit sub
End if
Errstr = "cannot connect to database"
'Connect to the database
Conn. connectionstring = "provider = microsoft. jet. oledb.4.0; data source =" + server. mappath (dbname)
Conn. open
Errstr = "an error occurred while executing the SQL statement"
'Execute SQL statements

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: 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.