title: Populating a WPF listbox with items from an SQL (SDF) database
body: <p>I have been searching on how to do this for a very long time, and I have not managed to get a straight answer on the subject, so hopefully one of you StackOverflow users will be able to help me here. I have a WPF ListBox named CategoryList and a SDF database called ProgramsList.sdf (with two tables called CategoryList and ProgramsList). What I wish my program to do is get the category names from the CategoryList table and list them in the ListBox control called CategoryList.</p>
  
  <p>Here's the code that I tried, but it only caused my program to crash.</p>
  
  <pre><code>    SqlConnection myConnection = new SqlConnection("Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "ProgramsList.sdf");
      SqlDataReader myReader = null;
  
      myConnection.Open();
      CategoryList.Items.Clear();
      SqlDataReader dr = new SqlCommand("SELECT Name FROM CategoryList ORDER BY Name DESC", myConnection).ExecuteReader();
  
      while (myReader.Read())
      {
          CategoryList.Items.Add(dr.GetInt32(0));
      }
      myConnection.Close();
  </code></pre>
  
  <p>Can anyone help me? Thanks in advance!</p>