Getting an exception saying: {"Fatal error encountered during command execution."}
on the following code:
internal string GetUserRole(string userEmail)
{
_query = "SELECT Role FROM RegisteredUsers WHERE Email = @userEmail";
string role = null;
using (_msqlCon = new MySqlConnection(_connectionString))
{
_msqlCon.Open();
using (_command = new MySqlCommand(_query, _msqlCon))
{
MySqlDataReader reader = _command.ExecuteReader();
while (reader.Read())
{
if (reader["Email"].Equals(userEmail))
{
role = reader["Role"].ToString();
break;
}
}
}
}
return role;
}
The innerException says: Parameter @userEmail
must be defined. This is the way I usually make a select statement when I have to select from the given parameter, so I guess it's just a minor error. But I have starred myself blind on this code for almost 20 min. What is wrong with my query: _query = "SELECT Role FROM RegisteredUsers WHERE Email = @userEmail";
?