当前位置:编程学习 > VB >>

VB listbox连接数据库

用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

上一个:VB读取文本文件记录
下一个:关于VB正则表达式

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,