如何从我的数据库填充我的列表视图 [英] How to populate my listview from my database
本文介绍了如何从我的数据库填充我的列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从我的数据库获取数据到listview
这是我打开和关闭我的连接的方式模块
查看sourceprint?
How to get data from my database to listview
This is how I open and close my connection from a module
view sourceprint?
Module CNT
Public Cnx As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public Sql As String
Public NomeUser As String
Sub Abrir()
Cnx.Open("dsn=ALUGUEL")
End Sub
Sub Fechar()
Cnx.Close()
End Sub
End Module
在每个程序中,我首先调用Abrir程序打开我的连接,然后关闭Fechar。
这是填充我的listView的程序
And on each procedure I call first the procedure Abrir to open my connection and Fechar to Close.
And this is the procedure to populate my listView
Sub Mostra()
ListView1.Items.Clear()
Call Abrir()
Sql = "Select * from V_Aluguel"
Rs.Open(Sql, Cnx, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic) Dim Li As ListViewItem
Li = ListView1.Items.Add(Rs.Fields("Marca").Value)
Li.SubItems(1) = Rs.Fields("Modelo").Value
Li.SubItems(2) = Rs.Fields("NumAlug").Value
Rs.Close()
Call Fechar()
End Sub
此代码只显示一个信息而不是我数据库中的所有信息
This code is just showing one information instead of all informations on my database
推荐答案
你应该调用 Rs.MoveNext
在循环中迭代所有查询结果。
You should call Rs.MoveNext
in a loop for iterating over all the query results.
这篇关于如何从我的数据库填充我的列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文