public static int Delete(Ukoly ukoly, Database pDb) { Database db; if (pDb == null) { db = new Database(); db.Connect(); } else { db = pDb; } SqlCommand command = db.CreateCommand(SQL_DELETE_ID); PrepareCommand(command, ukoly); int ret = db.ExecuteNonQuery(command); if (pDb == null) { db.Close(); } return(ret); }
private static void PrepareCommand(SqlCommand command, Ukoly ukoly) { command.Parameters.AddWithValue("@id_ukolu", ukoly.id_ukolu); command.Parameters.AddWithValue("@id_zodpovedneho_oddielu", ukoly.id_zodpovedneho_oddielu); command.Parameters.AddWithValue("@nazov", ukoly.nazov); command.Parameters.AddWithValue("@popis", ukoly.popis); }
public static Collection <Ukoly> SelectDetail(Ukoly u, Database pDb = null) { Database db; if (pDb == null) { db = new Database(); db.Connect(); } else { db = (Database)pDb; } SqlCommand command = db.CreateCommand(SQL_DETAIL); PrepareCommand(command, u); SqlDataReader reader = db.Select(command); Collection <Ukoly> ukoly = Read(reader); reader.Close(); if (pDb == null) { db.Close(); } return(ukoly); }
private static Collection <Ukoly> Read(SqlDataReader reader) { Collection <Ukoly> ukoly = new Collection <Ukoly>(); while (reader.Read()) { int i = -1; Ukoly ukol = new Ukoly(); ukol.id_ukolu = reader.GetInt32(++i); ukol.id_zodpovedneho_oddielu = reader.GetInt32(++i); ukol.nazov = reader.GetString(++i); ukol.popis = reader.GetString(++i); ukoly.Add(ukol); } return(ukoly); }