I've implemented the following code multiple times, but this time it gives me the error System.NullReferenceException: The object reference was not set to an object instance
Here is the code:
bool userExists = false;
string existCheck = "SELECT COUNT(*) FROM tablename WHERE name = @name;";
MySqlCommand cmd = new MySqlCommand(existCheck, connect);
cmd.Parameters.AddWithValue("@name", username);
int userCount = Convert.ToInt32(cmd.ExecuteScalar()); <- The error is produced here
if (userCount > 0)
{
userExists = true;
}
In another part of the project where I used the same code with other variables it works without problems.
Greetings