0

I am doing a project in vb.net and I've made a table with listview now the problem is that I am not be able to get a specific column item and only be able to get the item of first column (listview.selecteditems(0).text) and i.e. 0(zero)... ListView1.SelectedItems(1/2/3/so on).Text is not working.

My code is:

s = one_way.ListView1.SelectedItems(4).Text
cmd1 = New OleDbCommand("Select reference_no from Booking_Details", cn)
cmd1 = New OleDbCommand("insert into Booking_Details values(" & i & ",'" & one_way.ListView1.SelectedItems(0).Text & "','" & main.ComboBox1.Text & "','" & main.ComboBox9.Text & "','" & main.RadioButton2.Text & "','" & main.ComboBox2.Text & "','" & main.ComboBox4.Text & "','" & main.DateTimePicker2.Text & "','" & s & "',' ',' ','" & main.ComboBox5.Text & "','" & main.ComboBox6.Text & "','" & main.ComboBox7.Text & "')", cn)
cmd1.ExecuteNonQuery() 

s = one_way.ListView1.SelectedItems(4).Text
cmd1 = New OleDbCommand("Select reference_no from Booking_Details", cn)
cmd1 = New OleDbCommand("insert into Booking_Details values('" & s & "')", cn)
cmd1.ExecuteNonQuery()

Someone please help.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Krishna
  • 1
  • 3
  • i am assigning value to the 'string s' by getting the item from listview1.selecteditems(4).text.. its working perfect when it is 0 instead of 4 – Krishna Nov 18 '13 at 12:22

1 Answers1

0

In a listview, selecteditem(s) refers to the row. In order to add columns to it, you had to create and assign subitems and that is how you need to get the info back:

someInfo = listview.SelectedItems(X).SubItems(Z).Text

'SelectedItems(N).Text' is just returning the column 0 or item text.

your code is also ripe for a sql injection attack - you should use parameters: https://stackoverflow.com/a/16760887/1070452

Community
  • 1
  • 1
Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
  • but i have already made a table with that... i have screenshot of that how i can i show you?? – Krishna Nov 18 '13 at 12:36
  • I dont see how that has anything to do with it. You asked how to get at other columns in the ListView. If it has columns then it probably has subitems, and the above is how you would get at the values stored there...presumably for the SQL statement. The code you posted shows `SelectedItems` 0 and 4 - those are different items or rows. Most likely you really mean `SelectedItems(0).SubItems(4)`. – Ňɏssa Pøngjǣrdenlarp Nov 18 '13 at 15:58