Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I don't know why this is happening. I want to insert my listview data to to my other table but keeps on getting this error subitem is not a member of listview item. Please help me

What I have tried:

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
Posted
Updated 23-May-16 2:59am
Comments
Karthik_Mahalingam 23-May-16 7:27am    
in the code you are using correct syntax
item.SubItems(1)

if you use " item.SubItem(1)" you will get error.
SuRaj Dedhia 23-May-16 7:32am    
I am using this correctly as item.SubItems(1) . Then too getting error
Karthik_Mahalingam 23-May-16 7:35am    
from this line only?
Sergey Alexandrovich Kryukov 23-May-16 7:58am    
Probably not. The title of the question says "SubItem", not "SubItems".
—SA
SuRaj Dedhia 23-May-16 7:52am    
Yes. In code where subItems is there its giving error

1 solution

Asp ListView's ListViewDataItem[^] or ListViewItem[^] Classes doesnt contain Property called SubItems, so it wont work.
It is available in Windows Application ListView Control. ListViewItem.SubItems Property (System.Windows.Forms)[^]


you should search something like this Get values from listview item uisng FindControl [^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900