ASP代码如下:
<%
function GetRootID(ClassID)
DBPath=Server.MapPath("database.mdb")
set S_DB = server.CreateObject( "SQLCONN.DB")
S_DB.Conn_Open DBPath
response.Write("<br>数据库打开成功!")
GetRootID = S_DB.GetRootID(ClassID)
Set S_DB=nothing
end function
ClassID=22
response.Write("<br>查询 ClassID: "&ClassID)
RSRootID=GetRootID(ClassID)
response.Write("<br>根目录RootID: "&RSRootID)
%>
VB6.0 中新建ActiveX-DLL项目
点工程-引用-Microsoft ActiveX Data Objects 2.8 Library
工程名SQLCONN
类名DB
sqlconn.DLL代码如下:
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(DBPath)
Dim strCon As String
Set Conn = New ADODB.Connection
On Error GoTo errHandler:
strCon = "DBQ=" & DBPath & ";DRIVER={Microsoft Access Driver (*.mdb)};"
Conn.Open strCon
errHandler:
strError = "错误源:" & Err.Source & vbCrLf & "描述:" & Err.Description
Exit Function
End Function
Function GetRootID(ByVal ClassID)
Dim query
query = "select ClassID,RootID from ArticleClass where ClassID=" & 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
生成sqlconn.dll之后,在开始菜单中点运行 输入 regsrv32 d:/dll/sqlconn.dll 存放注册路径
在iis中测试运行asp 文件即可
参考网址http://www.jaron.cn/chs_scripts/8/2003-05/20030508152020-100943.html
此程序中的数据库表。连接方式都未搜集完全,只是调用了一个普通的连接。
相关数据库名称:database.mdb
数据表名称:ArticleClass
表中记录:ClassID(22),RootID(4)
详细请参考动易数据库就行了