public void UpdateObvestilo(string id, Obvetilo obvestilo) { SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "UPDATE Obvestilo SET naziv=@naziv, opis=@opis, datum_objave=@datum_objave WHERE id=@id"; cmd.Parameters.Add("ID", SqlDbType.Int).Value = int.Parse(id); cmd.Parameters.Add("Naziv", SqlDbType.VarChar).Value = obvestilo.naziv; cmd.Parameters.Add("Opis", SqlDbType.VarChar).Value = obvestilo.opis; cmd.Parameters.Add("Datum objave", SqlDbType.VarChar).Value = obvestilo.datum_objave; conn.Open(); try { int update = cmd.ExecuteNonQuery(); } catch (Exception ex) { } conn.Close(); }
//Novice ******************.........................************************ public List <Obvetilo> GetObvestila() { List <Obvetilo> obvestilo = new List <Obvetilo>(); SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT Id, naziv, opis, datum_objave FROM Obvestilo"; conn.Open(); try { SqlDataReader rd = cmd.ExecuteReader(); if (rd.HasRows) { obvestilo = new List <Obvetilo>(); while (rd.Read()) { Obvetilo o = new Obvetilo(); o = new Obvetilo(); o.id = rd.GetInt32(0); o.naziv = rd.GetString(1); o.opis = rd.GetString(2); o.datum_objave = rd.GetString(3); obvestilo.Add(o); } } } catch (Exception ex) { } conn.Close(); return(obvestilo); }
public void CreateObvestilo(Obvetilo obvestilo) { SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "INSERT INTO Obvestilo (naziv, opis, datum_objave) VALUES (@naziv, @opis, @datum_objave)"; cmd.Parameters.Add("Naziv", SqlDbType.VarChar).Value = obvestilo.naziv; cmd.Parameters.Add("Opis", SqlDbType.VarChar).Value = obvestilo.opis; cmd.Parameters.Add("Datum objave", SqlDbType.VarChar).Value = obvestilo.datum_objave; conn.Open(); try { int create = cmd.ExecuteNonQuery(); } catch (Exception ex) { } conn.Close(); }