0

For i = 1 To ListBox1.Items.Count - 1
cstr1 = ListBox1.Text
strqry1 = "insert into trans(pid) values('" & cstr1 & "')"
MessageBox.Show(strqry1)
If ListBox1.GetSelected(i) = True Then
cmd.CommandText = strqry1
cmd.ExecuteNonQuery()
End If
Next
MessageBox.Show("Records added")

the above code is for inserting multiple records frm listbox to table
but ony the first record gets added

needed help

2
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by Jx_Man
0

it causing your code just insert the selected item.
try to change cstr1 = ListBox1.Items.Item(i)
>> i = 1 --> its not starting with 1 but 0.
First item index is 0 not 1.

For i = 0 To ListBox1.Items.Count - 1
cstr1 = ListBox1.Items.Item(i)
strqry1 = "insert into trans(pid) values('" & cstr1 & "')"
'MessageBox.Show(strqry1)
'If ListBox1.GetSelected(i) = True Then
cmd.CommandText = strqry1
cmd.ExecuteNonQuery()
'End If
Next
MessageBox.Show("Records added")
0

actually i got a little confuse here. you want to insert all item in combobox or multiple selected?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.