11
Reply

Updating a MySQL database with items from a listview

Kevin Davis

Kevin Davis

May 7 2012 10:25 AM
5.3k
I have a listview with a few columns, and I'm trying to choose all items and add each of them to my MYSQL database online.  However, when I try to run the script, it will either only update the first record, or the last record, but never all the records.  Any help would be appreciated.  Thank you.

Dim strsql As String
        For i = 0 To ListView1.Items.Count - 1
            Dim a As String = ListView1.SelectedItems(i).SubItems(15).Text---------------------------Customer Name Column
            Dim b As Integer = CInt(ListView1.SelectedItems(i).Text)------------------------------------Id Number of Customer
            'strsql = "Update orders SET Name = '" & ListView1.SelectedItems(i).SubItems(15).Text & "' where ID = '" & ListView1.SelectedItems(i).Text & "'"
          
        strsql = "Update orders SET Name = '" & a & "' where ID = '" & b & "'"
        Dim da As New MySqlDataAdapter(strsql, CONNECTION)

        Next

        da.Fill(ds)

I've tried a couple different ways of doing this, and it "partially" works either way.  I also get a error stating that "the integer i will not be inferred as it is bound to a filed in an enclosing scope."

Thanks again for any help.

Zcast
   

Answers (11)