This question has already been answered:
Hi HashCode, I have a code
private void btnAddAdv_Click(object sender, EventArgs e) { if (textUrl.Text == "" || numBalance.Value == 0) { MessageBox.Show("Заполните все поля", "Системное сообщение"); } else { MySqlConnection cnt = new MySqlConnection(strProvider); try { cnt.Open(); MySqlCommand command = cnt.CreateCommand(); command.CommandText = "SELECT * FROM t_user WHERE username='" + textUserName.Text + "' and pass='" + Convert.ToString(textPassword.Text) + "'"; MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { if (Convert.ToInt32(reader["balance"]) <= 0 && Convert.ToInt32(reader["balance"]) < Convert.ToInt32(numBalance.Value)) { MessageBox.Show("Недостатовно средств", "Системное сообщение"); } else { MySqlCommand balancecmd = cnt.CreateCommand(); balancecmd.CommandText = "SELECT balance FROM t_user WHERE username='" + textUserName.Text + "' and pass='" + Convert.ToString(textPassword.Text) + "'"; balancecmd.ExecuteNonQuery(); MySqlCommand cmd = cnt.CreateCommand(); cmd.CommandText = "UPDATE t_user SET balance = balance - 50 - '" + numBalance.Value + "' WHERE username='" + textUserName.Text + "' and pass='" + Convert.ToString(textPassword.Text) + "'"; cmd.ExecuteNonQuery(); MessageBox.Show("Сайт добавлен", "Системное сообщение"); } } cnt.Close(); reader.Close(); } catch (MySqlException ee) { MessageBox.Show(ee.Message, "Системное сообщение"); } }
This code should compare the value from the Database and if they are greater than zero and greater than the value of the numBalace element, display a message that the balance does not have enough funds ... otherwise, make that code in the else block, but I have an error
There is already an open DataReader associated with this Connection.