public static void UpdateZoo(ListBox listBoxZoo, ZooModel zooModel) { string query = @"Update Zoo set Location = @Location where Id = @ZooID"; SqlCommand sqlCommand = new SqlCommand(query, sqlConnection); using (sqlCommand) { sqlCommand.Parameters.AddWithValue("@ZooID", listBoxZoo.SelectedValue); sqlCommand.Parameters.AddWithValue("@Location", zooModel.Location); sqlCommand.Connection.Open(); sqlCommand.ExecuteScalar(); sqlCommand.Connection.Close(); } }
public static void AddZoo(ZooModel zooModel) { string addZooRecord = @"insert into Zoo (Location) values (@Location)"; SqlCommand addZooCommand = new SqlCommand(addZooRecord, sqlConnection); using (addZooCommand) { addZooCommand.Parameters.AddWithValue("@Location", zooModel.Location); addZooCommand.Connection.Open(); addZooCommand.ExecuteScalar(); addZooCommand.Connection.Close(); } }
private void AddZoo_Clicked(object sender, RoutedEventArgs e) { ZooModel zooModel = new ZooModel(); zooModel.Location = textZoo.Text; try { DbConnectionManager.AddZoo(zooModel); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { textZoo.Text = ""; ShowZooList(); } }
private void UpdateZoo_Clicked(object sender, RoutedEventArgs e) { ZooModel zooModel = new ZooModel(); zooModel.Location = textZoo.Text; try { DbConnectionManager.UpdateZoo(listBoxZoo, zooModel); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { if (listBoxZoo.SelectedItem != null) { ShowZooList(); textZoo.Text = ""; } } }