Calling ExecuteNonQuery for a SELECT statement is totally wrong. This method should be used when you expect to know how many rows are affected by an INSERT/UPDATE/DELETE statement (or other Data Definition Language queries)
You should use ExecuteReader and check if the reader HasRows == True.
But if you are just interested to know if that particular user with the specified type exists then you can use a different query text that could be run by ExecuteScalar (returns a single row/column value)
string cmdText = @"IF EXISTS(Select 1 from dbo.Admin
where Type=2 and UserName=@user)
SELECT 1 ELSE SELECT 0";
using(SqlConnection myConn = new SqlConnection(myConnection))
using(SqlCommand SelectCommand = new SqlCommand(cmdText, myConn))
{
myConn.Open();
SelectCommand.Parameters.Add("@user", SqlDbType.NVarChar).Value = l1.UserName.Text;
int i = (int)SelectCommand.ExecuteScalar();
if (i > 0)
{
btnAdminPanel.Hide();
}
}
This query returns 1 if there is a record that satisfies the condition or zero if there is no record. It is better because the database will execute this query knowing that you are interested only in the existence of the record and not on the content of the record. From the client side this is better because the NET library doesn't need to build an SqlDataReader to read an unknown number of records and you don't need to check for null return values.
Also note that I have used parameters to pass the query values. Never use string concatenations if you want to avoid hackers throw a party with your code. Sql Iniection is based on this string concatenation approach.
Finally disposable objects go inside a using block to avoid resources leaks.