Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset cn.Provider = "Microsoft.Jet.OLEDB.3.51" cn.ConnectionString = DataPath cn.Open rs.CursorType = adOpenKeyset rs.LockType = adLockOptimistic Set rs.ActiveConnection = cn rs.Open (SQL) set text1.datasource=rs text1.datafiled=rs.fields(0).name
建立一个dsn,然后 Public Cn As New ADODB.Connection Public rs As ADODB.Recordset Cn.Open "dsn=Mndsoft" Set rs = New ADODB.Recordset
With rs .CursorType = adOpenKeyset .LockType = adLockOptimistic .Source = "select * from PowerSupply" .ActiveConnection = Cn .Open For i = 0 To .RecordCount - 1 Combo1.AddItem .Fields(3) & Space(2) & .Fields(2) .MoveNext Next Combo1.ListIndex = 0 .Close End With
Public ConnectString As String Public Connect As New ADODB.Connection '连接到数据库 ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\data.mdb;" Connect.Open ConnectString '下面就是访问数据库了 Dim temp As New ADODB.Recordset Dim itxm As ListItem temp.Open "select * from [User]", Connect, 3, 2 If temp.RecordCount <> 0 Then Label1.Caption = "共有注册人员" & temp.RecordCount & "人" temp.MoveFirst Do While temp.EOF = False Set itxm = ListView1.ListItems.Add(, "S" & temp.Fields(1), temp.Fields(2)) itxm.SubItems(1) = temp.Fields(1) itxm.SubItems(1) = temp.Fields(3) If temp.Fields(5) = 1 Then itxm.SubItems(2) = "在线" If temp.Fields(5) = 0 Then itxm.SubItems(2) = "不在线" temp.MoveNext Loop End If temp.Close Set temp = Nothing
Dim rs As New ADODB.Recordset
cn.Provider = "Microsoft.Jet.OLEDB.3.51"
cn.ConnectionString = DataPath
cn.Open
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
Set rs.ActiveConnection = cn
rs.Open (SQL)
set text1.datasource=rs
text1.datafiled=rs.fields(0).name
Public Cn As New ADODB.Connection
Public rs As ADODB.Recordset Cn.Open "dsn=Mndsoft"
Set rs = New ADODB.Recordset
With rs
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Source = "select * from PowerSupply"
.ActiveConnection = Cn
.Open
For i = 0 To .RecordCount - 1
Combo1.AddItem .Fields(3) & Space(2) & .Fields(2)
.MoveNext
Next
Combo1.ListIndex = 0
.Close
End With
Public Connect As New ADODB.Connection
'连接到数据库
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\data.mdb;"
Connect.Open ConnectString
'下面就是访问数据库了
Dim temp As New ADODB.Recordset
Dim itxm As ListItem
temp.Open "select * from [User]", Connect, 3, 2
If temp.RecordCount <> 0 Then
Label1.Caption = "共有注册人员" & temp.RecordCount & "人"
temp.MoveFirst
Do While temp.EOF = False
Set itxm = ListView1.ListItems.Add(, "S" & temp.Fields(1), temp.Fields(2))
itxm.SubItems(1) = temp.Fields(1)
itxm.SubItems(1) = temp.Fields(3)
If temp.Fields(5) = 1 Then itxm.SubItems(2) = "在线"
If temp.Fields(5) = 0 Then itxm.SubItems(2) = "不在线"
temp.MoveNext
Loop
End If
temp.Close
Set temp = Nothing