I am trying to Delete a Token from my SQL Database after it has been used.
MySqlCommand cmdSel = new MySqlCommand("SELECT * FROM tokens WHERE token = " + int.Parse(passbox.Text), dbCon);
MySqlDataReader dbRead = cmdSel.ExecuteReader();
if (dbRead.Read())
{
int sqlkey = int.Parse(dbRead["token"].ToString());
if (keyint == sqlkey)
{
using (MySqlCommand delTok = new MySqlCommand("DELETE FROM tokens WHERE token = " + keyint, dbCon))
{
delTok.ExecuteNonQuery(); //MAIN PROBLEM HERE.
/*
MySql.Data.MySqlClient.MySqlException: 'There is already an open DataReader associated with this Connection which must be closed first.'
*/
//ERROR ^^^^^^
}
try
{
dbCon.Close();
loading loading = new loading();
loading.Show();
this.Hide();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}
do i have to close the DataReader or is there some way else, and how do i close the reader? i want to Delete the token once the if keyint is sqlkey statement is true/done. the Error only shows once i try to execute the script for the if statement. The "token" is an int(10)