Monday 19 December 2016

How to Connect Listview with Database and Load data into Listview-Step ...

Visual Basic 6.0 Tutorial :How to Connect Listview control with Microsoft  Access Database and  Load data into the Listview control-Step by Step Guide.
STEP:1
Create a Database Using Microsoft Access.
I have already created a database named"Logindataappmdb"and Table "Log".
STEP:2
1.Add ADO Library for database Connectivity
2. Add Listview Control onto VB Project.
STEP:3
Add ColumnHeaders to the Listview.
(For  Rollno,Name,Class,Section,Stream)
STEP:4
Create Objects for Database Connection and  Recordset in General Declaration Section

 
Code.
Dim connect As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub Form_Load()
With ListView1.ColumnHeaders
.Add , , "RollNo", Width / 5, lvwColumnLeft
.Add , , "Name", Width / 5, lvwColumnCenter
.Add , , "Class", Width / 5, lvwColumnCenter
.Add , , "Section", Width / 5, lvwColumnCenter
.Add , , "Stream", Width / 5, lvwColumnCenter
End With
loaddata
End Sub

Sub dbconnection()
connect.Open "Provider=Microsoft.jet.OLEDB.4.0;Data Source=D:\Database Folder\Logindataapp.mdb"
End Sub

Sub loaddata()
Dim list As ListItem
ListView1.ListItems.Clear
dbconnection
rs.Open "Select * from Log", connect, adOpenDynamic, adLockOptimistic
Do Until rs.EOF
Set list = ListView1.ListItems.Add(, , rs!RollNo)
list.SubItems(1) = rs!Name
list.SubItems(2) = rs!Class
list.SubItems(3) = rs!Section
list.SubItems(4) = rs!Stream
rs.MoveNext
Loop
End Sub

for more Visual Basic tutorials,please visit 
Youtube Channel:https://www.youtube.com/user/sandydehrian
Computer Gyan Blog:http://selfcomputerlearning.blogspot.in/

3 comments:

  1. Thanks for sharing great informational content. It helped me alot in many ways.
    grabify

    ReplyDelete
  2. Usually I do not read article on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been amazed me. Thanks, quite nice article. apple kundenservice berlin

    ReplyDelete
  3. Extremely helpful. Thank you very much.

    ReplyDelete