title: SQL Server Column to Combobox?
body: <p>I have a table called <code>Product</code>. One of the columns of this table is called <code>Naam</code>. It's the name of the product. When you press on the button, all product names have to be added to the combobox.</p>
  
  <p>So if I have 2 products: Cola &amp; Fanta.</p>
  
  <p>The program has to show only the column <code>Naam</code> in the combobox. Not the other columns.</p>
  
  <p>I have already this for my button, but it doesn't work. </p>
  
  <pre><code>db.AlleProducten("Select Naam from Product;", Product);
  cb_product.Items.Add(Product.Naam);
  </code></pre>
  
  <p>And this is the method that runs the query:</p>
  
  <pre><code>public void AlleProducten(string commandText, product Product)
  {
      using (SqlConnection conn = new SqlConnection(connectionString))
      using (SqlCommand cmd = new SqlCommand(commandText, conn))
      {
          conn.Open();
  
          using (var rdr = cmd.ExecuteReader())
          {
               if (rdr.HasRows)
               {
                   rdr.Read();
                   Product.Naam = rdr.GetString(1);
                   conn.Close();
               }
          }
      }
  }
  </code></pre>
  
  <p>The error:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll</p>
    
    <p>Additional information: De index ligt buiten de matrixgrenzen.</p>
  </blockquote>
  
  <p>The additional information is in Dutch. Translated to English:</p>
  
  <blockquote>
    <p>The index is located outside of the array bounds.</p>
  </blockquote>