I am puzzled by why it does not retrieve the data and keep saying i have a error "InvalidCastException", i am currently doing these in compact framework and is totally new to it, i searched around looking for a way to get data into a listview base on what little i know about java . these are my creation of table and inserting during formload
Dim createTable3 As SqlCeCommand = connection.CreateCommand
createTable3.CommandText = "CREATE TABLE product(product_id int IDENTITY(0,1) PRIMARY KEY,product_name nvarchar(50),bought_price float,sales_price float)"
connection.Open()
createTable3.ExecuteNonQuery()
Dim insertCmd2 As SqlCeCommand = connection.CreateCommand
insertCmd2.CommandText = "INSERT INTO product(product_name,bought_price)Values('Food',1.00)"
insertCmd2.ExecuteNonQuery()
Dim insertCmd3 As SqlCeCommand = connection.CreateCommand
insertCmd3.CommandText = "INSERT INTO product(product_name,bought_price)Values('Orange',1.50)"
insertCmd3.ExecuteNonQuery()
Dim insertCmd4 As SqlCeCommand = connection.CreateCommand
insertCmd4.CommandText = "INSERT INTO product(product_name,bought_price)Values('Apple',3.00)"
insertCmd4.ExecuteNonQuery()
Dim insertCmd5 As SqlCeCommand = connection.CreateCommand
insertCmd5.CommandText = "INSERT INTO product(product_name,bought_price)Values('Fruit',2.00)"
insertCmd5.ExecuteNonQuery()
connection.Close()
this is a code for a get info button
Dim itmListItem As ListViewItem
Dim shtFieldCntr As Short
Dim loopCmd As SqlCeCommand = connection.CreateCommand
loopCmd.CommandText = "SELECT * FROM product"
connection.Open()
Dim dr As SqlCeDataReader = loopCmd.ExecuteReader
Do While dr.Read
itmListItem = New ListViewItem()
If dr.IsDBNull(dr(0)) Then
itmListItem.Text = ""
Else
itmListItem.Text = dr(0)
End If
For shtFieldCntr = 1 To dr.FieldCount()
If dr.IsDBNull(shtFieldCntr) Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(dr.GetString(shtFieldCntr)) ' error this line
End If
Next shtFieldCntr
lvProduct.Items.Add(itmListItem)
Loop
connection.Close()
picture