SQL Server 2008 で c# を使用しています。データベースから多数の日付を読み取りたいプロジェクトを作成しています。これらの日付は、1 つずつ 1 つの列に格納されます。そして、取得したデータをリストに追加する必要があります。
私のコードは次のようなものです:
public List<DateTime> 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<DateTime> list=new List<DateTime>();
foreach (DataRow row in table.Rows)
{
DateTime dt = new DateTime();
dt = Convert.ToDateTime(row["holiday"]);
list.Add(dt);
}
conn.Close();
return list;
}