Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to refresh and display database data in listview on button click in vb.net win form. and clicking on a particular row of that listview another listview should display the all data from same database in the same form.
can anyone provide me the exact code for this..its urgent..
Posted

1 solution

Here you go you might have to change some of the code though ill walk you through it :P
VB
Dim db_con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "DATABASE LOCATION GOES HERE)

        db_con.Open()

        Dim ds As New DataSet

        Dim query1 As String
        query1 = " SELECT * FROM TABLEGOESHERE"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(query1, db_con)
        da.Fill(ds, "VirusMD5")
        Dim tblstr As String = Nothing
        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader
        Dim _Ecount As Integer
        _Ecount = ds.Tables("THE TABLE YOU NEED TO READ FROM").Rows.Count
        signatures = _Ecount
        cmd = New OleDbCommand("SELECT * FROM VirusMD5", db_con)
        dr = cmd.ExecuteReader
        While dr.Read
             'You need to figure out how many items their are and what you are reading. See link below
             Combobox1.Items.Add(dr(0))
'0 Stands for the first items rows are handled automatically.

        End While


        GoTo ende



        End If
        ende:


This image will help your with the items and rows part of it (rows and columes always start at 0)
www.homeandlearn.co.uk/NET/images/vb_2010/addressBook_ACCESS_p280.jpg[^]


I do not do anything we listviews because I am not familiar with it but getting the data from the database is the same.
To make it do what you want to do edit this part of the code.
VB
Combobox1.Items.Add(dr(0))

Replace that line with adding data to your listveiw. Hope this helps
 
Share this answer
 
Comments
mjubin 7-Nov-12 0:28am    
no..its not working...:(
ExcelledProducts 7-Nov-12 15:23pm    
What is your error? Also try it with a combo box because that is what the original code is for also make sure you change the db_con, query1, and everything that has tables. Also i know it works because it is used in my program.
mjubin 8-Nov-12 23:56pm    
i tried but its not working for my project.. i have display User name,date of joining,company name in one listview,..on click of particular User_Name or full row of listview i want to display full user information like gender,address contact number in another listview where user name is selected row and company name is selected row.
ExcelledProducts 9-Nov-12 9:38am    
Oh so you are getting information from different items so you use dr(0) for the first colum, dr(1) for the second colum, and so on. So say you Username is the first colum then you use dr(0), if it is in the second colum then it would be dr(1)

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