title: Dataset Loading a WPF Combobox
body: <pre><code>DataSet dataSet = new DataSet();
  using (SqlConnection connection = new SqlConnection("server=server;   database=database; user id=user; password=user"))
  {
       connection.Open();
       using (SqlCommand command = new SqlCommand("SELECT DISTINCT ID FROM TABLE ORDER BY ID ASC", connection))
       {
            SqlDataAdapter reader = new SqlDataAdapter(command);
            reader.Fill(dataSet);
            IDComboBox.DataContext = dataSet; --&gt; This doesn't work
            IDComboBox.Itemsource = dataSet.Tables[0].Columns[0].ToString() --&gt; doesn't work
            IDComboBox.Itemsource = dataSet.Tables[0].Rows[0].ToString() --&gt; doesn't work
            IDComboBox.Itemsource = dataSet.Tables[0].Rows --&gt; doesn't work
            IDComboBox.Itemsource = dataSet.Tables[0].Columns --&gt; doesn't work
            They don't work even with me pairing it the IDComboBox.DataContext = dataSet.Tables[0].Rows[0] or Columns[0]
       }
       connection.Close();
       connection.Dispose();
  }
  </code></pre>
  
  <p>I am needing to fill my combobox in a WPF with the data from my datatable. All I keep finding are the examples that use Combobox.Displaymember, Combobox.Source to do this but a C# WPF application doesn't have these options. How can I load a WPF combobox with data from a dataset or a datatable?  </p>
  
  <p>One way that I was doing it before was</p>
  
  <pre><code>  using (SqlConnection connection = new SqlConnection("server=server; database=database; user id=user; password=user"))
    {
        connection.Open();
        using (SqlCommand command = new SqlCommand("SELECT DISTINCT ID FROM Table ORDER BY ID ASC", connection))
        {
             SqlDataReader reader = command.ExecuteReader();
             while (reader.Read())
             {
                 for (int i = 0; i &lt; reader.FieldCount; i++)
                 {
                     IDComboBox.Items.Add(reader[i].ToString());
                 }
             }
         }
         connection.Close();
         connection.Dispose();
    }
  </code></pre>
  
  <p>I know having it for looped into my combobox is very slow if I have large amounts of data so I am wanting to dump it in from a dataset to reduce run time. </p>