I'm trying to check if a username with the given passwort exists in my database, if it exists it should return true otherwise it should return false.
My current function looks like the following:
public bool user_check(string username, string password)
{
string query = "SELECT username, password from swear_tool where username='" + username + "' and password = '" + password + "'";
if (this.OpenConnection() == true)
{
MySqlCommand cmd = new MySqlCommand(query, connection);
MySqlDataReader dataReader = cmd.ExecuteReader();
if (dataReader.HasRows)
{
while (dataReader.Read())
{
return true;
}
}
else
{
return false;
}
dataReader.Close();
this.CloseConnection();
}
}
But I receive the following error message:
Error CS0161 'database_connector.user_check(string, string)': not all code paths return a value
What am I doing wrong?