hello buddy,
I have a problem about listview update data
the first I input data from textbox to listview, after listview have many data/row, I want to update data only one click button use query WHERE ID
the problem : I just can save first row only, not all or only by selected..
How to update all data in listview

mycode :

If ListView1.Items.Count > 0 Then
            strSQL = "Update errorlog set errorreport = errorreport - '" & ListView1.Items(0).SubItems(1).Text & "' where idreport = '" & ListView1.Items(0).SubItems(0).Text & "'"
            Dim da As New MySqlDataAdapter(strSQL, CONNECTION)
        End If

please, help to fix it ..
thank you :)

Edited by awanz: n/a

6 Years
Discussion Span
Last Post by Begginnerdev

You will want to create a listview item, and then bind the .text of the listview item to a unique value(primary key) then build the item and add it to the listview.


dim itmListView as New ListViewItem

'Random value, substitute it with your own.
itmListView.Text = iamunique

'Next add your values
'Example is if myValues was a datatable.
for i = 0 to myValues.rows.count - 1

You can get your data from the data adapter by creating a data set and data table then passing it through.

'da = Data Adapter, ds = Dataset, MyValues = datatable
da.fill (ds,"tablename")
MyValues = ds.SelectTable("tablename")

To safeguard from NULL references, try this.

'Place a try catch block and an extra if for added protection.

   If MyValues isnot Nothing Then

     'Your code here.

   End IF

Catch ex as Exception
   MsgBox("Oops!" & vbcrlf & ex.message")
End try

Hope this helps

Edited by Begginnerdev: n/a


This code read multiple row ?? .. and your code using sql server, I'm use Mysql reference ..
flow my code are :
1. Insert to listview use button addlist
2. When I think enough e.g listview

ID ErrorReportTotal
1001 20
2002 30
3003 10

3. click button update and run connection then all data in listview has updated by ID Report

but I don't how to all data in listview updated, my code only selected or the first row .. :(


You will have to redraw the listview. I normally use a chain of sub procedures to:

1) Design (Columns)
2) Get Data (Data Reader)
3) Fill the listview

You can create this in one procedure, but I made it 3 for flexibility.

I hope this helps.

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.