Deze regel is fout
using (conn = new MySqlConnection(cs));
Verwijder de puntkomma en neem alles op dat de MySqlConnection-variabele nodig heeft in een {}
blok
using (MySqlConnection conn = new MySqlConnection(cs))
{
// No need to test if the connection is not open....
conn.Open();
.........
// Not needed (at least from your code above
// MySqlDataAdapter MyAdapter2 = new MySqlDataAdapter();
// MyAdapter2.SelectCommand = myCommand2;
... calcs follow here
// Attention here, if the query returns null (no input match) this line will throw
oldpoints = (int)myCommand2.ExecuteScalar();
.... other calcs here
MySqlCommand cmdDataBase = new MySqlCommand(query, conn);
cmdDataBase.Parameters.Add("@input", SqlDbType.Int).Value = Convert.ToInt32(textBox2.Text);
cmdDataBase.Parameters.AddWithValue("@Points", new_points);
cmdDataBase.Parameters.AddWithValue("@Rewards", new_rewards);
cmdDataBase.Parameters.AddWithValue("@Transaction", textBox3.Text);
cmdDataBase.Parameters.AddWithValue("@TransationDate", transaction_date);
// Use ExecuteNonQuery for INSERT/UPDATE/DELETE and other DDL calla
cmdDataBase.ExecuteNonQuery();
// Not needed
// MySqlDataReader myReader2;
// myReader2 = cmdDataBase.ExecuteReader();
// Not needed, the using block will close and dispose the connection
if(conn.State == ConnectionState.Open)
conn.Close();
}
Er is ook een andere fout in de laatste vraag. Er ontbreekt een spatie tussen de parameter @TransactionDate en de WHERE-component. In gevallen waar een lange SQL-opdrachttekst nodig is, vind ik de letterlijke voortzetting van de tekenreeksregel @
erg handig
string query = @"UPDATE members Set [email protected], [email protected],
[email protected], [email protected]
WHERE id = @input;";