VB listbox连接数据库

来源:百度知道 编辑:UC知道 时间:2024/05/20 02:02:03
用listbox连接数据库并显示数据库的某一列的信息。
比如要求在listbox中显示数据库中的用户名。
越详细越好,最好不要改控件的名称!。
小弟在这先谢谢拉。!!!

‘以下我用ADODC帮你写了。
‘数据库=Student
'资料表=Class1
'栏位="Student_Name

Private Sub Command1_Click()
With Adodc1
List1.Clear
.Recordset.MoveFirst
Do While Not .Recordset.EOF
List1.AddItem (.Recordset.Fields("Student_Name").Value)
.Recordset.MoveNext
Loop
End With
End Sub

Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\student.mdb" & ";Persist Security Info=False"
Adodc1.CursorLocation = adUseClient
Adodc1.CursorType = adOpenKeyset
Adodc1.LockType = adLockOptimistic
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from class1"
Adodc1.Refresh
End Sub