public static void Update(Mesto m) { using (var conn = new SQLiteConnection(ConfigurationManager.ConnectionStrings["Dijagnoze"].ConnectionString)) { conn.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = "UPDATE mesto SET mesto = @mesto WHERE id = @id"; cmd.Parameters.AddWithValue("Id", m.Id); cmd.Parameters.AddWithValue("mesto", m.MestoStanovanja); cmd.ExecuteNonQuery(); } //azuriranje modela foreach (var mesto in Aplikacija.Instance.Mesto) { if (m.Id == mesto.Id) { mesto.MestoStanovanja = m.MestoStanovanja; } } }
public static ObservableCollection <Mesto> GetAll() { var mesto = new ObservableCollection <Mesto>(); using (var conn = new SQLiteConnection(ConfigurationManager.ConnectionStrings["Dijagnoze"].ConnectionString)) { SQLiteCommand cmd = conn.CreateCommand(); SQLiteDataAdapter da = new SQLiteDataAdapter(); cmd.CommandText = "SELECT * FROM Mesto"; da.SelectCommand = cmd; DataSet ds = new DataSet(); da.Fill(ds, "mesto"); foreach (DataRow row in ds.Tables["mesto"].Rows) { var m = new Mesto(); m.Id = int.Parse(row["Id"].ToString()); m.MestoStanovanja = row["Mesto"].ToString(); mesto.Add(m); } } return(mesto); }
public static Mesto Create(Mesto m) { using (var conn = new SQLiteConnection(ConfigurationManager.ConnectionStrings["Dijagnoze"].ConnectionString)) { conn.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = "INSERT INTO mesto (mesto) VALUES(@mesto)"; cmd.Parameters.AddWithValue("mesto", m.MestoStanovanja); cmd.ExecuteNonQuery(); } Aplikacija.Instance.Mesto.Add(m); return(m); }