0

I want to add my Listview data to another database table. I went through some tutorials & found following solution. However it keeps showing the error :

"SubItems is not a member of ListViewItem"

Private Sub orderButton_Click(sender As Object, e As EventArgs) Handles orderButton.Click
    Try
        For Each item As ListViewItem In myCart.Items
            Dim sql As New StringBuilder
            sql.AppendLine(" INSERT INTO newMedicinesOrders ")
            sql.AppendLine(" ( ")
            sql.AppendLine(" ,medicineName")
            sql.AppendLine(" ,power")
            sql.AppendLine(" ,form")
            sql.AppendLine(" ,fQuantity")
            sql.AppendLine(" ,iQuantity")
            sql.AppendLine(" ,type")
            sql.AppendLine(" ,cost")
            sql.AppendLine(" ) ")
            sql.AppendLine(" VALUES ")
            sql.AppendLine(" ( ")
            sql.AppendLine(" ,'" & item.SubItems(1).Text & "' ")
            sql.AppendLine(" ,'" & power.Text & "' ")
            sql.AppendLine(" ,'" & Form.Text & "' ")
            sql.AppendLine(" ,'" & fQuantity.Text & "' ")
            sql.AppendLine(" ,'" & iQuantity.Text & "' ")
            sql.AppendLine(" ,'" & Type.Text & "' ")
            sql.AppendLine(" ,'" & iCost.Text & "' ")
            sql.AppendLine(" ,'" & Type.Text & "' ")
            sql.AppendLine(" ) ")
            Dim command As New MySqlCommand
            command.CommandText = sql.ToString
            command.Connection = con2
            command.ExecuteNonQuery()
        Next
    Catch ex As Exception
        Response.Write(ex)
    End Try
End Sub
Abdellah OUMGHAR
  • 3,627
  • 1
  • 11
  • 16

1 Answers1

0

This is for C#. Please look here:

Getting SubItem from listview

You need to use:

item.SubItems[1].Text

But I notice your tag is for c# and vb.net and your code is actually vb.net.

Community
  • 1
  • 1
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164