By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,077 Members | 886 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,077 IT Pros & Developers. It's quick & easy.

Loop listbox and insert

OuTCasT
100+
P: 374
I have a listbox on my form that has items that the user has chosen, i need to loop through the listbox and get the values and insert them into a sql table.

Can anyone hlp?
Jan 26 '09 #1
Share this Question
Share on Google+
2 Replies

debasisdas
Expert 5K+
P: 8,127
use the index of items selected.
Jan 27 '09 #2

OuTCasT
100+
P: 374
Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim i As Integer
  3. Dim strString As String
  4. For i = 0 To ListBox2.Items.Count - 1
  5. strString = ListBox2.Items(i)
  6. MsgBox(strString)
  7. sqlCon = New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=test;Integrated Security=True")
  8. sqlCon.Open()
  9. sqlCommand = New SqlCommand("insert into employee(EarningLineNO,EmployeeCode)values('" & strString & "','001')", sqlCon)
  10. sqlCommand.ExecuteNonQuery()
  11. sqlCon.Close()
  12. Next i
  13.  
Jan 27 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.