0

ahmm, please help me. I want to update the items in listview when my form loads up.

this is my code for the listview. It actually displays the data on the database but when
i add another data it wont appear on the listview.
please help me guys. I'll appreciate it much.
im using vb.net 2005

Sub list()
con.Open()
cmd = New OleDbCommand("select * from employee", con)
conreader = cmd.ExecuteReader()


Me.ListView2.Items.Clear()
Dim lv As ListViewItem
Do While conreader.Read
lv = Me.ListView2.Items.Add(conreader.Item("empno"))
lv.SubItems.Add(conreader.Item("fname"))
lv.SubItems.Add(conreader.Item("middle"))
lv.SubItems.Add(conreader.Item("lname"))
lv.SubItems.Add(conreader.Item("age"))
lv.SubItems.Add(conreader.Item("address"))
lv.SubItems.Add(conreader.Item("datereg"))
lv.SubItems.Add(conreader.Item("fullname"))
Loop
cmd.Dispose()
con.Close()

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by vanzhyme
0

what i mean for another data is it when i save another data to the database i want
that new data will be viewed in the list view when form loads up.

0

hi

create a sub or function of the code that u have written
on Form_LOad Event..

when ever u add new data to database call this new created sub and it will populate the list with the new data.

0

Why don't you post the entire code here so we can have a look, and let the code speak for you. Thanks

0

thank you so much guys for the idea. i have solve it now.
as of now im stuck with the part that if i want to the the data on the listview.
after i click the data i will automatically appear on the textbox below.
sorry for the inconvenient im still a newbie. please help me

this my code for loading the data on listview.

Sub list()
con.Open()
cmd = New OleDbCommand("select * from employee", con)
conreader = cmd.ExecuteReader()


Me.ListView2.Items.Clear()
Dim lv As ListViewItem
Do While conreader.Read
lv = Me.ListView2.Items.Add(conreader.Item("empno"))
lv.SubItems.Add(conreader.Item("fname"))
lv.SubItems.Add(conreader.Item("middle"))
lv.SubItems.Add(conreader.Item("lname"))
lv.SubItems.Add(conreader.Item("age"))
lv.SubItems.Add(conreader.Item("address"))
lv.SubItems.Add(conreader.Item("datereg"))
lv.SubItems.Add(conreader.Item("fullname"))
Loop
cmd.Dispose()
con.Close()

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.