How to connect a database in a COM component

Source: Internet
Author: User
/* Written by Jaron, 2003-05-10 * *
* Original Source: Jiangdu Information Network http://www.jiangdu.net * *
* Reprint Please specify the source and retain this copyright information * *
* * Welcome to use Sitemanager Website Management System http://sitemanager.cnzone.net * *
vb-Engineering-Reference-ADO 2.0, build a class DB, project name is set to Sqlconn
Here are some of the code in my program, you can try it sometime
Option Explicit
Public strerror as String
Public Conn as New ADODB. Connection
Public Rs as New ADODB. Recordset
Public Property Get ErrorString () as String
ErrorString = strerror
End Property
Public Function Conn_open (Strsqlservername, Strsqldbusername, Strsqldbpassword, Strsqldbname)
Dim Strcon as String
Set Conn = New ADODB. Connection
On Error GoTo ErrHandler:
Strcon = "PROVIDER=SQLOLEDB; Server= "& Strsqlservername &"; User id= "& Strsqldbusername &"; Password= "& Strsqldbpassword &";D atabase= "& Strsqldbname &";
Conn.Open Strcon
ErrHandler:
strerror = "error Source:" & Err.Source & vbCrLf & "description: & Err.Description
Exit Function
End Function
Function Getrootid (ByVal ClassID)
Dim Query
query = "Select Class_id,rootid from tblcategory where class_id= '" & ClassID & "'"
Set Rs = conn.execute (query)
If not (rs.eof and RS.BOF) Then
Getrootid = Rs ("Rootid")
Else
Getrootid = ClassID
End If
Rs.close
Set Rs = Nothing
End Function
After compiling, this is used in ASP
Function Getrootid (ByVal ID) ' Gets the root class ID number
Set s_db = Server. CreateObject ("Sqlconn.") DB ")
s_db. Conn_open Strsqlservername,strsqldbusername,strsqldbpassword,strsqldbname
Getrootid = s_db. Getrootid (ID)
Set s_db=nothing
End Function

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.