1 Replies - 502 Views - Last Post: 19 December 2013 - 10:23 AM Rate Topic: -----

#1 iamLazy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 04-December 13

Updating multiple records involving Listview

Posted 19 December 2013 - 09:49 AM

I have this sample table as reference
Posted Image

My problem is how to update multiple data basing on listview record

http://www.dreaminco...1&#entry1948176

I'm stuck with this problem,

I have this sample code though its for textbox,

I retrieve the product.quantity from database and substract it with inputted quantity of the customer then update it.

        Try

            Dim sql2 As String = "UPDATE PRODUCT SET qty = @quantity WHERE productID = @productID"

            Dim x As New Integer
            Dim y As New Integer
            Dim total As New Integer

            x = Val(txtProductQty.text)
            y = Val(txtcustomerQty.text)
            total = x - y

           
            cmd = New MySqlCommand(sql2, CNN)
            cmd.Parameters.AddWithValue("@quantity", total)
            cmd.Parameters.AddWithValue("@productID", txtProdID.text)
            cmd.ExecuteNonQuery()
            MessageBox.Show("UPDATED")

        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try

    End Sub




So how about in a listview? I cant' get it work on listview on multiple records,

Also I tried even just 1 selected record in a listview and it's not working

cmd.Parameters.AddWithValue("@productID", listview1.selecteditems(0).subitems(3).text)



I'm developing a POS for our project in school . Please any help, tips or hints .

Is This A Good Question/Topic? 0
  • +

Replies To: Updating multiple records involving Listview

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Updating multiple records involving Listview

Posted 19 December 2013 - 10:23 AM

That would only work if the item was selected.

You should be able to use:
cmd.Parameters.AddWithValue("@productID", listview1.items(0).subitems(3).text)


With multiple items, you could use a for...each (again, using the items collection and not the selecteditems collection)
or you could use a for...next and use the iterator variable in your items(i) to move through each index of the collection.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1