网上找了个连接数据库的类Public conn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public addFlag As Boolean
Public Function OpenCn() As Boolean
Dim mag As String
On Error GoTo strerrmag
Set conn = New ADODB.Connection
conn.ConnectionTimeout = 25
conn.Provider = "sqloledb"
conn.Properties("data source").Value = "KRISCN" '服务器的名字
conn.Properties("initial catalog").Value = "版本号" '库名
conn.Properties("integrated security").Value = "SSPI" '登陆类型
conn.Open
OpenCn = True
addFlag = True
Exit Function
strerrmag:
mag = "无法连接"
Call MsgBox(mag, vbOKCancel, "Error:Data connect")
addFlag = False
End
End Function
Public Sub clocn()
On Error Resume Next
If conn.State <> adStateClosed Then conn.Close
Set conn = Nothing
End SubPublic Function openrs(ByVal strsql As String) As Boolean '连接数据库记录集
Dim mag As String
Dim rpy As Boolean
On Error GoTo strerrmag
Set rs = New ADODB.Recordset
If addFlag = False Then rpy = True
With rs
.ActiveConnection = conn
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open strsql
End With
addFlag = True
openrs = True
Exit Function
strerrmag:
mag = "data not connect"
Call MsgBox(mag, vbOKCancel, "error:connect")
openrs = False
End
End Function
Public Sub clors()
On Error Resume Next
If rs.State <> adStateClosed Then rs.Clone
Set rs = Nothing
End Sub
我在Command1中加入
Private Sub Command1_Click()Call OpenCn
Call openrs("版本号")Call clocn
Call clorsEnd Sub连接好了然后我想的到里面的数据该怎么做????