I have a database and want to check if a specific record already exists.
string sql = "SELECT COUNT(*) from tbl_student WHERE email = '" + mail + "' AND telephone= '" + telephone + "'";
NpgsqlCommand command = new NpgsqlCommand(sql, conn);
int userCount = (int)command.ExecuteScalar();
if (userCount > 0)
{
lblMessage.Text = "Person already exists";
}
The line that is not working. The error message says it is an invalid cast. I have no clue, please help me.
int userCount = (int)command.ExecuteScalar();