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()

How do you add the "another data"?

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.

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.

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

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()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.