public List <Raison> ObtenirListeRaison() { SqlConnection cnn = null; var connetionString = Properties.Settings.Default.dbConnectionString; var raisons = new List <Raison>(); cnn = new SqlConnection(connetionString); const string sql = "SELECT * FROM Raison r "; try { cnn.Open(); var command = new SqlCommand(sql, cnn); var dataReader = command.ExecuteReader(); while (dataReader.Read()) { var raison = new Raison { CodeRaison = dataReader.GetValue(0).ToString(), DescRaison = dataReader.GetValue(1).ToString() }; raisons.Add(raison); } dataReader.Close(); command.Dispose(); cnn.Close(); } catch (Exception ex) { // MessageBox.Show("Can not open connection ! "); } return(raisons); }
public List<Raison> ObtenirListeRaison() { SqlConnection cnn = null; var connetionString = Properties.Settings.Default.dbConnectionString; var raisons = new List<Raison>(); cnn = new SqlConnection(connetionString); const string sql = "SELECT * FROM Raison r "; try { cnn.Open(); var command = new SqlCommand(sql, cnn); var dataReader = command.ExecuteReader(); while (dataReader.Read()) { var raison = new Raison { CodeRaison = dataReader.GetValue(0).ToString(), DescRaison = dataReader.GetValue(1).ToString() }; raisons.Add(raison); } dataReader.Close(); command.Dispose(); cnn.Close(); } catch (Exception ex) { // MessageBox.Show("Can not open connection ! "); } return raisons; }