title: How to get a single column data (one by one) from a database using c# and how to add it to a list
body: <p>I am using c# with SQL Server 2008. I am craeting a project, in which I want to read a number of dates from a database. These dates are stored in a single column as one by one. And the retrieved data should be added to a list.</p>
  
  <p>My code is like this:</p>
  
  <pre><code>public List&lt;DateTime&gt; getholidays()
  {
      DataTable table = new DataTable("holidays");
  
      SqlCommand command = new SqlCommand();
      command.Connection = conn;
      command.CommandType = System.Data.CommandType.Text;
      command.CommandText = "select holiday from holidays";
  
      //conn.Open();
      SqlDataAdapter adapter = new SqlDataAdapter(command);
      adapter.Fill(table);
  
      List&lt;DateTime&gt; list=new List&lt;DateTime&gt;();
  
      foreach (DataRow row in table.Rows)
      {
          DateTime dt = new DateTime();
          dt = Convert.ToDateTime(row["holiday"]);
          list.Add(dt);
      }
  
      conn.Close();
      return list;
  }
  </code></pre>