eu preciso de puchar somente um valor de uma tabela do sql, que eu estarei usando este valor para definir os usuários as roles, irá funcionar assim,

o usuario loga, então é criada uma conexção no banco de dados e nesta conexão ele verifica em qual role este usuario esta em então ele coloca o usuario na role,

o codigo que eu estou usando é este.

SqlConnection Conection = new SqlConnection(ConfigurationManager.ConnectionStrings["MarketingConnectionString"].ToString());
        SqlCommand consulta = new SqlCommand("SELECT REGRA FROM TblUsuariosExecutive WHERE Nome = 'victor'", Conection);
        SqlDataReader Dreader = null;
        try
        {
            Conection.Open();
            Dreader = consulta.ExecuteReader();

            while (Dreader.Read())
            {
                adm.Text = Dreader.ToString();
             
            }
        }
        catch
        {
            adm.Text = "ocorreu um erro";
        }
        finally
        {
            Dreader.Close();
            Conection.Close();
        }

if you want just one row one column in return use in the select statement do this
SELECT TOP 1 REGRA FROM TblUsuariosExecutive WHERE Nome = 'victor'

then in the SqlCommand execute the ExecuteScalar method that will return just one value as an Object just convert that to your data you are expecting.

An alternative without modifying the sql command would be to change how you run the query:

Change:
Dreader = consulta.ExecuteReader();

To:
Dreader = consulta.ExecuteScalar();

Execute scalar grabs only the first row, even if there are multiple results.

make query select top 1 * from table order by id desc

U can use any Top 1 Metode or ExecuteScalar As Explain Above As per i said Use Execute Sclar It will Speed Up Ur Application

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.