1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
/// <summary>
/// Obtention de la liste de tout les projets
/// </summary>
/// <returns></returns>
public static List<Project> All()
{
SqlConnection connection = ConnectionDB.GetConnection();
List<Project> projects = new List<Project>();
try
{
//Parametrage et execution de la requete
String query = @"SELECT Identifier, Name, IsEnded, EstimatedCost,Deadline FROM Project";
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Project project = new Project();
project.Identifier = reader.GetInt32(0);
project.Name = reader.GetString(1);
project.IsEnded = reader.GetBoolean(2);
project.EstimatedCost = (double)reader.GetDecimal(3);
project.Deadline = reader.GetDateTime(4);
projects.Add(project);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
finally
{
ConnectionDB.CloseConnection();
}
return projects;
} |
Partager