private void btnAdd_Click(object sender, EventArgs e) { try { if (txtbPrice.Text != string.Empty && txtProductName.Text != string.Empty) //check if all fields are filled { string isActive = chkActive.Checked ? "1" : "0"; string sqlQuery = "INSERT INTO items (productName, productPrice, isActive ) VALUES ('" + txtProductName.Text + "','" + txtbPrice.Text + "', '" + isActive + "'); "; //insert data MySQLconnection con = new MySQLconnection(); con.Executing(sqlQuery); loadTable(); } else { MessageBox.Show("Please fill all the fields", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void deleteData(int row) { string ID = dgvItems.Rows[row].Cells[0].Value.ToString(); string sqlQuery = "DELETE FROM items WHERE ID = '" + ID + "';"; MySQLconnection con = new MySQLconnection(); con.Executing(sqlQuery); //Load Table loadTable(); }
private void btnSave_Click(object sender, EventArgs e) { try { if (txtbPrice.Text != string.Empty && txtProductName.Text != string.Empty) //check if all fields are filled { string isActive = chkActive.Checked ? "1" : "0"; string sqlQuery = "UPDATE items SET productName = '" + txtProductName.Text + "', productPrice = '" + txtbPrice.Text + "', isActive = '" + isActive + "' WHERE ID = '" + Item.ID + "';"; //update data MySQLconnection con = new MySQLconnection(); con.Executing(sqlQuery); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }