public void deleteMethod() { try { packages.mysql.mysqlSettings mySqlSettings = new packages.mysql.mysqlSettings(); string query = String.Format("DELETE FROM {0}.{1} WHERE {2} = {3}", packages.mysql.mysqlSettings.dbSchema, table, "id", index); using (MySqlConnection mySqlConnection = new MySqlConnection(packages.mysql.mysqlSettings.connectionString)) { using (MySqlCommand mySqlCommand = new MySqlCommand(query, mySqlConnection)) { mySqlConnection.Open(); dataGrid.ItemsSource = mySqlSettings.getData(query).DefaultView; } mySqlConnection.Close(); } } catch (MySqlException ex) { if (ex.Number == 1451) { MessageBox.Show("Успадковані дані неможливо видалити.", "Помилка при видаленні", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show(ex.Message, ex.Source); } } }
private void populateComboBox() { packages.mysql.mysqlSettings database = new packages.mysql.mysqlSettings(); string query = String.Format("SELECT id, name FROM {0}.{1}", packages.mysql.mysqlSettings.dbSchema, foreignTable ); database.createConnection(); using (database.initSqlCommand(query)) { database.openConnection(); inputDivision.DisplayMemberPath = "name"; inputDivision.SelectedValuePath = "id"; inputDivision.ItemsSource = database.getData(query).DefaultView; } database.closeConnection(); }
private void loadServices() { packages.mysql.mysqlSettings database = new packages.mysql.mysqlSettings(); string query = String.Format("SELECT id, name, price_per_unit FROM {0}.{1}", packages.mysql.mysqlSettings.dbSchema, "services" ); database.createConnection(); using (database.initSqlCommand(query)) { database.openConnection(); listServices.SelectedValuePath = "id"; listServices.DisplayMemberPath = "name"; listServices.ItemsSource = database.getData(query).DefaultView; } database.closeConnection(); }