title: storing selected items from listbox for sql where statement
body: <p>I wanted to get all the selected items from the listbox for sql where statement in a button I have a code</p>
  <pre><code>Imports System.Data.OleDb
  Public Class Form1
  
      Dim conString As String = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\jp\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\TestDb.mdb&quot;
      Dim con As OleDbConnection = New OleDbConnection(conString)
      Dim cmd As OleDbCommand
      Dim adapter As OleDbDataAdapter
      Dim dt As DataTable = New DataTable()
      Private selectedIndices As New List(Of Integer)
  
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
          Dim tempo = ListBox6.GetItemText(ListBox6.SelectedItems())
          Dim Studente As String = &quot;&quot;
          For Each selected In tempo
              Studente = selected.ToString &amp; &quot;,&quot; &amp; Studente
          Next
          UpdateLVe(Studente)
  
      End Sub
  </code></pre>
  <p>and I have a method</p>
  <pre><code>Private Sub UpdateLVe(ByVal Studente As String)
  
      Dim sql As String = &quot;UPDATE peace SET Votes = Votes + 1 WHERE Student='&quot; &amp; Studente &amp; &quot;'&quot;
  
      cmd = New OleDbCommand(sql, con)
  
      Try
          con.Open()
          adapter = New OleDbDataAdapter(cmd)
  
          adapter.UpdateCommand = con.CreateCommand()
          adapter.UpdateCommand.CommandText = sql
  
          If cmd.ExecuteNonQuery() &gt; 0 Then
              MsgBox(&quot;Successfully Voted&quot;)
          End If
  
          con.Close()
      Catch ex As Exception
          MsgBox(ex.Message)
          con.Close()
  
      End Try
  
  End Sub
  </code></pre>