MySqlDataReader Hasn't Row But Query has data

76 Views Asked by At

My Query in PHPmyadmin has result but in C#, a.read() returns no data.

string query = "SELECT answer FROM tbl WHERE level = " + level + " AND subject = '" + subject[i] + "';";

MySqlCommand command = new MySqlCommand(query, connection);
connection.Open();
MySqlDataReader a = command.ExecuteReader();
while (a.Read())
{
    //Do Some Things
}
connection.Close();

Edit: I've already tried parameterized queries, didn't work, and also tried with the constant values from the table, it doesn't work in the project, but when I run the query in the database it works

0

There are 0 best solutions below