本帖最后由 作者 于 2004-4-20 20:14:28 编辑
给你一个完整代码吧- Private mycon As New ADODB.Connection
- Private myrs As New ADODB.Recordset
- Public Datas As Variant
- Private Sub Class_Initialize()
- mycon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db1.mdb;Persist Security Info=False"
- mycon.Open
- myrs.ActiveConnection = mycon
- myrs.CursorType = adOpenDynamic
- myrs.CursorLocation = adUseClient
- myrs.Open "select * from dee where id=1001"
- End Sub
- Private Sub Class_Terminate()
- myrs.Close
- End Sub
- Public Sub Find(Index As String)
- Dim pDatas() As Variant
- myrs.Close
- myrs.CursorType = adOpenDynamic
- myrs.CursorLocation = adUseClient
- myrs.Open "select * from dee where id=" & Trim(Index)
- ReDim pDatas(myrs.Fields.Count - 1) As Variant
- For i = o To myrs.Fields.Count - 1
- pDatas(i) = myrs.Fields(i)
- Next i
- Datas = pDatas
- End Sub
注意:红色部分的数据库路径要给全将上述代码存为Clsdb类,在程序中用下列方式调用- Sub test()
- Dim a As New clsDB
- a.Find "1001"
- MsgBox a.Datas(2)
- End Sub
|