VB6代码:
-----------------------------------------------------
Private Conn As ADODB.Connection
Private Rs As ADODB.Recordset
'作用:判断数据库是否正确连接
Public Function GetConn() As Boolean
??? Set Conn = New ADODB.Connection
???
??? Conn.Open "Provider=abc.mdb"
???
??? If Err.Number <> 0 Then
???
??????? GetConn = False
???????
??? Else
???
??????? GetConn = True
???????
??? End If
???
End Function
'根据输入的 Id , 得到记录
Public Function GetName(strId As Integer) As String
??? Dim strSql As String
???
??? Set Rs = New ADODB.Recordset
???
??? strSql = "SELECT * FROM [User] WHERE UserId = " & strId
???
??? Rs.Open strSql, Conn, adOpenStatic, adLockBatchOptimistic
???
??? If Rs.EOF Then
???
??????? GetName = ""
???????
??? Else
???
??????? GetName = Rs.Fields(0)
???????
??? End If
???
??? Rs.Close
???
End Function
Public Function CloseDB()
??? Conn.Close
???
End Function
?
ASP调用组件代码:
-----------------------------------------------------
<%
Dim DataQuery
Dim strId
Dim strResult
Dim Flag
SET DataQuery = Server.CreateObject("WebDb.GetInfomation")
Flag = DataQuery.GetConn()
Response.Write Flag & "
"
Response.Write DataQuery.GetName(10)
DataQuery.CloseDB()
SET DataQuery = Nothing
%>