private void button1_Click(object sender, EventArgs e) { ProductForm PF = new ProductForm(); if (PF.ShowDialog() == DialogResult.OK) { try { cmd.CommandText = @"INSERT INTO products (name, weight, price) VALUES ('" + PF.name.Text + "'," + PF.weight.Text + "," + PF.price.Text.Replace(",", ".") + ")"; cmd.ExecuteNonQuery(); this.GetAllProducts(); } catch (Exception a) { MessageBox.Show(a.Message); } } }
private void button2_Click(object sender, EventArgs e) { this.EditItem = this.listView1.SelectedItems[0]; ProductForm PF = new ProductForm(); PF.name.Text = this.EditItem.SubItems[0].Text; PF.price.Text = this.EditItem.SubItems[1].Text; PF.weight.Text = this.EditItem.SubItems[2].Text; if (PF.ShowDialog() == DialogResult.OK) { try { cmd.CommandText = @"UPDATE products SET name = '" + PF.name.Text + "', price = " + PF.price.Text.Replace(",", ".") + ", weight = " + PF.weight.Text + " WHERE id = " + this.EditItem.SubItems[3].Text; cmd.ExecuteNonQuery(); this.GetAllProducts(); } catch (Exception a) { MessageBox.Show(a.Message); } } }