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)
            da.Fill(ds)
            Me.Refresh()
            MsgBox("Success")
        Else
            MsgBox("Error")
        End If

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

Recommended Answers

All 3 Replies

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.

Example:

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
itmListView.Subitems.Add(myValues.rows(i).Item(0))
next
MyListView.items.add(itmListView)

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.

Try
   
   If MyValues isnot Nothing Then

     'Your code here.

   End IF

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

Hope this helps

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)
-Calls-
2) Get Data (Data Reader)
-Calls-
3) Fill the listview

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


I hope this helps.

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.