Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 



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
Posted
Updated 12-Aug-14 10:15am
v2
Comments
Member 11008741 12-Aug-14 16:02pm    
This code is just showing one information instead of all informations on my database

1 solution

You should call Rs.MoveNext in a loop for iterating over all the query results.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900