最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
COM组件中如何连接数据库
时间:2022-06-30 11:13:58 编辑:袖梨 来源:一聚教程网
/* written by Jaron ,2003-05-10 */
/* 原出处:江都资讯网 http://www.ji*a*ng*du.net */
/* 转载请注明出处和保留此版权信息 */
/* 欢迎使用SiteManager网站管理系统 http://sitemanager.*c**nzone.net */
VB- 工程 -引用 - ADO 2.0 ,建一个类DB,工程名设为 SQLCONN
以下是偶程序中的部分代码,大家有空可以试试
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 & ";Database=" & strSQLDBName & ";"
Conn.Open strCon
errHandler:
strError = "错误源:" & Err.Source & vbCrLf & "描述:" & 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
编译后,在ASP中这样用
function GetRootID(byval id) ' 获取根类ID号
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
/* 原出处:江都资讯网 http://www.ji*a*ng*du.net */
/* 转载请注明出处和保留此版权信息 */
/* 欢迎使用SiteManager网站管理系统 http://sitemanager.*c**nzone.net */
VB- 工程 -引用 - ADO 2.0 ,建一个类DB,工程名设为 SQLCONN
以下是偶程序中的部分代码,大家有空可以试试
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 & ";Database=" & strSQLDBName & ";"
Conn.Open strCon
errHandler:
strError = "错误源:" & Err.Source & vbCrLf & "描述:" & 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
编译后,在ASP中这样用
function GetRootID(byval id) ' 获取根类ID号
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
相关文章
- 蚂蚁森林神奇海洋2026年4月20日答案 05-15
- 胖折叠的终极形态 华为Pura X Max上手评测 05-15
- 2026年4月将从Xbox Game Pass库中移除的所有游戏 05-15
- 《Pragmata》首发销量突破100万份 为全新单机IP注入希望 05-15
- 《Pragmata》两天内销量突破一百万份 05-15
- DNF奇美拉技能链设置推荐 05-15