public static int Insert(Pracovne_smeny smeny, Database pDb) { Database db; if (pDb == null) { db = new Database(); db.Connect(); } else { db = pDb; } SqlCommand command = db.CreateCommand(SQL_INSERT); PrepareCommand(command, smeny); int ret = db.ExecuteNonQuery(command); if (pDb == null) { db.Close(); } return(ret); }
private static void PrepareCommand(SqlCommand command, Pracovne_smeny smeny) { command.Parameters.AddWithValue("@id_smeny", smeny.id_smeny); command.Parameters.AddWithValue("@id_typ_ukolu", smeny.id_typ_ukolu); command.Parameters.AddWithValue("@id_letu", smeny.id_letu); command.Parameters.AddWithValue("@pid", smeny.pid); command.Parameters.AddWithValue("@datum", smeny.datum); command.Parameters.AddWithValue("@smena", smeny.smena); }
private static Collection <Pracovne_smeny> Read(SqlDataReader reader) { Collection <Pracovne_smeny> smeny = new Collection <Pracovne_smeny>(); while (reader.Read()) { int i = -1; Pracovne_smeny smena = new Pracovne_smeny(); smena.id_smeny = reader.GetInt32(++i); smena.id_typ_ukolu = reader.GetInt32(++i); smena.id_letu = reader.GetInt32(++i); smena.pid = reader.GetString(++i); smena.datum = reader.GetDateTime(++i); smena.smena = reader.GetInt32(++i); smeny.Add(smena); } return(smeny); }