public static int insertToDB(int id, string SerialNumber, int amount) { int return_code = 0; string transactionDate = DateTime.Now.ToShortDateString() + ' ' + DateTime.Now.ToShortTimeString(); string insertStatement = "UPDATE inv_products " + "SET amount = amount + @amount, last_added = now() " + "WHERE id = @id;"; MySqlConnection connection = AddAmount.GetConnection(); MySqlCommand insertCommand = new MySqlCommand(insertStatement, connection); insertCommand.Parameters.AddWithValue("@id", id); insertCommand.Parameters.AddWithValue("@serial", SerialNumber); insertCommand.Parameters.AddWithValue("@lastAdded", transactionDate); insertCommand.Parameters.AddWithValue("@amount", amount); try { connection.Open(); insertCommand.ExecuteNonQuery(); return_code = 1; } catch (MySqlException ex) { throw ex; } finally { connection.Close(); } return(return_code); }
private void buttonAdd_Click(object sender, EventArgs e) { int id = Convert.ToInt32(comboBoxID_Add.SelectedValue); string SerialNumber = Convert.ToString(comboBoxSerial_Add.SelectedItem); int amount = Convert.ToInt32(textBox1.Text); AddAmount.insertToDB(id, SerialNumber, amount); /* Example code * int userID = Convert.ToInt32(comboBox1.SelectedValue); * int TransactionCode = Convert.ToInt32(comboBox2.SelectedItem); * int itemID = Convert.ToInt32(textBox1.Text); * FinalDB.insertToDB(userID, itemID, TransactionCode); */ }