static void Main()
{
List<MyClass> list = new List<MyClass>();
using(SqlConnection sql = new SqlConnection("Data Source=Your_Server;Initial Catalog=Your_Database;Integrated Security=SSPI;"))
{
sql.Open();
using(SqlCommand command = new SqlCommand("SELECT id, name, date FROM mytable WHERE date > @date", sql))
{
command.Parameters("@date", DateTime.Now);
DataTable table = new DataTable();
SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = command;
dataAdapter.Fill(table);
foreach(DataRow row in table.Rows)
{
list.Add(new MyClass
{
id = (int)row["id"],
name = (string)row["name"],
date = (DateTime)row["date"]
});
}
}
}
}
class MyClass
{
public int id;
public string name;
public DateTime date;
}