title: VB.NET How to use ExecuteReader well
body: <p>Here is a code :</p>
  <pre><code>Private Sub ComboBoxQC1L1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBoxQC1L1.SelectedIndexChanged
  
          Dim conn As New SqlConnection
          If conn.State = ConnectionState.Closed Then
              conn.ConnectionString = (&quot;Data Source=.\SQLEXPRESS;Initial Catalog=OST;Integrated Security=True&quot;)
  
          End If
  
          Try
              conn.Open()
              Dim sqlquery As String = &quot;SELECT * FROM liste_unités where nom_unité = &quot; &amp; ComboBoxC1L1.Text &amp; &quot;&quot;
  
              Dim data As SqlDataReader
              Dim adapter As New SqlDataAdapter
              Dim command As SqlCommand = New SqlCommand(sqlquery, conn)
  
              command.Connection = conn
              adapter.SelectCommand = command
              data = command.ExecuteReader()
              While data.Read
  
                  If ComboBoxQC1L1.Text = &quot;ordinaire&quot; Then
                      LabelPointsC1L1.Text = XXX
                  ElseIf ComboBoxQC1L1.Text = &quot;élite&quot; Then
                      LabelPointsC1L1.Text = XXX
                  ElseIf ComboBoxQC1L1.Text = &quot;médiocre&quot; Then
                      LabelPointsC1L1.Text = XXX
                  End If
  
              End While
          Catch ex As Exception
  
          End Try
  
      End Sub
  </code></pre>
  <p><a href="https://i.stack.imgur.com/4nfEk.jpg" rel="nofollow noreferrer">Here is the app overview</a></p>
  <p><a href="https://i.stack.imgur.com/ISSMm.jpg" rel="nofollow noreferrer">Here is the SQL table overview</a></p>
  <p>Into the ComboBoxC1L1, all the &quot;nom_unité&quot; are populated and the LabelC1L1 is changing with the corresponding &quot;cout_unité&quot;</p>
  <p>Ex : When ComboBoxC1L1.text = &quot;Arbalétrier&quot;, LabelC1L1.text = &quot;7&quot;. If the ComboBoxC1L1.SelectedIndex is changing, the LabelC1L1.text is changing to.</p>
  <p>Now introducing the ComboBoxQC1L1 with 3 possible values : &quot;ordinaire&quot;, &quot;médiocre&quot; and &quot;élite&quot;.</p>
  <p>I want the LabelPointsC1L1.text to adapt to the correct values (see table overview) while the ComboBoxQC1L1 is changing.</p>
  <p>Ex : When ComboBoxC1L1.text = &quot;Arbalétrier&quot;, LabelC1L1.text = &quot;7&quot;.
  If ComboBoxQC1L1.text is changing from &quot;ordinaire&quot; to &quot;élite&quot;, LabelC1L1.text should become &quot;9&quot;.
  If ComboBoxQC1L1.text is changing from &quot;ordinaire&quot; to &quot;médiocre&quot;, LabelC1L1.text should become &quot;5&quot;.
  At last, if ComboBoxQC1L1.text is changing to &quot;ordinaire&quot;, LabelC1L1.text should become &quot;7&quot; like initially.</p>
  <p>I'm trying to figure by what code should I replace the &quot;XXX&quot; in the code to do this ?</p>
  <p>Many thanks :-)</p>