public List <HoraireModel> GetAll() { List <HoraireModel> laListe = new List <HoraireModel>(); // 1 - Connexion SqlConnection oConn = new SqlConnection(); // 1.1 Chemin vers le serveur ==> connectionString oConn.ConnectionString = @"Data Source=26R2-4\WADSQL;Initial Catalog=MedicoDB;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"; // 1.2 Ouvrir la connexion try { oConn.Open(); // 2 - Commande SqlCommand oCmd = new SqlCommand(@"select * from Horaire where DebDate<= GETDATE() and FinDate>= GETDATE()" , oConn); //Forme longue //SqlCommand oCmd = new SqlCommand(); //oCmd.Connection = oConn; //oCmd.CommandText = "select.."; // 3 - Execute SqlDataReader oDr = oCmd.ExecuteReader(); // 3.1 - Lire toutes les lignes while (oDr.Read()) { HoraireModel HM = new HoraireModel(); HM.IdHoraire = (int)oDr["idHoraire"]; HM.Jour = (string)oDr["Jour"]; HM.DebMat = (TimeSpan)oDr["DebMat"]; HM.FinMat = (TimeSpan)oDr["FinMat"]; HM.DebAprem = (TimeSpan)oDr["DebAprem"]; HM.FinAprem = (TimeSpan)oDr["FinAprem"]; HM.DebDate = (DateTime)oDr["DebDate"]; HM.FinDate = (DateTime)oDr["FinDate"]; laListe.Add(HM); } // 3.2 - Fermer le reader oDr.Close(); // 4 - Fermer la connexion oConn.Close(); } catch (Exception) { throw; } return(laListe); }
public List <HoraireModel> GetAll() //1-Connexion { List <HoraireModel> laliste = new List <HoraireModel>(); SqlConnection oConn = new SqlConnection(); //1.1 Xhemin vers le serveur ==> ConnectionString oConn.ConnectionString = @"Data Source=26R2-09\WADSQL;Initial Catalog=MedicoDB;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"; //1.2 Ouvrir la connexion try //Ctrl+K+S { oConn.Open(); //2 - Commande SqlCommand oCmd = new SqlCommand(@"SELECT * FROM Horaire WHERE DebDate<= GETDATE() and FinDate >= GETDATE()" , oConn); //3 - Execute SqlDataReader oDr = oCmd.ExecuteReader(); //3.1 - Lire toutes les lignes //3.1 - Lire toutes les lignes while (oDr.Read()) { HoraireModel HM = new HoraireModel(); HM.IdHoraire = (int)oDr["IdHoraire"]; HM.Jour = oDr["Jour"].ToString(); HM.DebtMat = (TimeSpan)oDr["DebMat"]; HM.FinMat = (TimeSpan)oDr["FinMat"]; HM.DebAprem = (TimeSpan)oDr["DebAprem"]; HM.FinAprem = (TimeSpan)oDr["FinAprem"]; HM.DebDate = (DateTime)oDr["DebDate"]; HM.FinDate = (DateTime)oDr["FinDate"]; laliste.Add(HM); } //3.2 - Fermer le reader oDr.Close(); //4 - Ferme la connexion oConn.Close(); } catch (Exception) { throw; } return(laliste); }
public List <HoraireModel> GetAll() { List <HoraireModel> LaListe = new List <HoraireModel>(); // 1 - Connexion SqlConnection oConn = new SqlConnection(); // chemin vers serveur (connection string) oConn.ConnectionString = @"Data Source=26R2-12\WADSQL;Initial Catalog=MedicoDB;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"; // ouvrir la connection try { oConn.Open(); // 2 - Commande SqlCommand oCmd = new SqlCommand(@"SELECT * FROM Horaire WHERE DebDate <= GETDATE() and FinDate >= GETDATE()", oConn); // 3 - Execute SqlDataReader oDr = oCmd.ExecuteReader(); // lire ttes les lignes while (oDr.Read()) { HoraireModel HM = new HoraireModel(); HM.IdHoraire = (int)oDr["idHoraire"]; HM.Jour = oDr["Jour"].ToString(); HM.DebMat = (DateTime)oDr["DebMat"]; HM.FinMat = (DateTime)oDr["FinMat"]; HM.DebAprem = (DateTime)oDr["DebAprem"]; HM.FinAprem = (DateTime)oDr["FinAprem"]; HM.DebDate = (DateTime)oDr["DebDate"]; HM.FinDate = (DateTime)oDr["FinDate"]; return(LaListe.Add(HM)); } // ferme reader oDr.Close(); // ferme connection oConn.Close(); } catch (Exception) { throw; } return(LaListe); }
public List <HoraireModel> GetAll() { List <HoraireModel> LaListe = new List <HoraireModel>(); //************************************************* // 1 CONNEXION : SqlConnection oConn = new SqlConnection(); // 1.1 chemin vers le serveur => ConnectionString : oConn.ConnectionString = @"Data Source=26R2-6\WADSQL;Initial Catalog=MedicoDB;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"; // 1.2 Ouvrir la connexion : (controle k s pour le try catch) try { oConn.Open(); //************************************************ // 2 COMMANDE : SqlCommand oCmd = new SqlCommand(@"select * FROM Horaire WHERE DebDate <= GETDATE() AND FinDate >= GETDATE()" , oConn); // Forme longue : //SqlCommand oCmd = new SqlCommand(); //oCmd.Connection = oConn; //oCmd.CommandText = "bla bla"; //************************************************ // 3 EXECUTE : SqlDataReader oDr = oCmd.ExecuteReader(); // 3.1 Lire toute les lignes : while (oDr.Read()) { HoraireModel HM = new HoraireModel(); HM.IdHoraire = (int)oDr["idHoraire"]; HM.Jour = oDr["Jour"].ToString(); HM.DebMat = (TimeSpan)oDr["DebMat"]; HM.FinMat = (TimeSpan)oDr["FinMat"]; HM.DebAprem = (TimeSpan)oDr["DebAprem"]; HM.FinAprem = (TimeSpan)oDr["FinAprem"]; HM.DebDate = (DateTime)oDr["DebDate"]; HM.FinDate = (DateTime)oDr["FinDate"]; LaListe.Add(HM); } // 3.2 Fermer le reader : oDr.Close(); // 4 FERMER LA CONNEXION : oConn.Close(); } catch (Exception) { throw; } return(LaListe); }