ASPCodeAs follows:
<%
Function getrootid (classid)
Dbpath = server. mappath ("database. mdb ")
Set s_db = server. Createobject ("sqlconn. DB ")
S_db.conn_open dbpath
Response. Write ("<br> the database is successfully opened! ")
Getrootid = s_db.getrootid (classid)
Set s_db = nothing
End Function
Classid = 22
Response. Write ("<br> query classid:" & classid)
Rsrootid = getrootid (classid)
Response. Write ("<br> root directory rootid:" & rsrootid)
%>
Create an ActiveX-DLL project in VB6.0
Point project-reference-Microsoft ActiveX Data Objects 2.8 Library
Project name sqlconn
Class Name DB
The sqlconn. DLL Code is as follows:
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 = "Error Source:" & err. Source & vbcrlf & "Description:" & 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
After sqlconn. dll is generated, run the following command in the Start Menu: Enter regsrv32 D:/dll/sqlconn. DLL to store the registration path.
Test the ASP file in IIS.
Reference Web site http://www.jaron.cn/chs_scripts/8/2003-05/20030508152020-100943.html
database table in the Program . The connection method is not completely collected, but a common connection is called.
related database name: database. MDB
data table name: articleclass
Table Record: classid (22), rootid (4)
For details, refer to the manual database.