Jump to content

Retirar valor de um select [RESOLVIDO]


Sergio990
 Share

Recommended Posts

Boas.

Como é que posso retirar um valor de um select?

O meu codigo é:

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cadastramentoGlobalConnectionString"].ConnectionString);
        SqlCommand portasDisponiveis = new SqlCommand();
        portasDisponiveis.CommandText = "DECLARE @idInterconect AS INT SET @idInterconect = '"+DDL_idInterconect.Text+"' SELECT M.NPortas-P.Qt Expr1 FROM Interconect I INNER JOIN Module M ON M.IdModule = I.IdModule CROSS APPLY (SELECT Count(1) Qt FROM Portas P WHERE P.IdInterconect = I.IdInterconect) P WHERE I.IdInterconect = @idInterconect";
        portasDisponiveis.Connection = con;
        
        con.Open();
        SqlDataReader reader = portasDisponiveis.ExecuteReader();
        lbl_nPortasDisponiveis.Text = reader["Expr1"].ToString();
        con.Close();

Eu queria retirar o valor do Select, mas nao sei o que colocar dentro do reader. Pois o que eu coloco da erro.

Obrigado 😉

Ps: O codigo do Select é do User: edgarzigne

Link to comment
Share on other sites

Ok assunto resolvido 😉

 SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cadastramentoGlobalConnectionString"].ConnectionString);
        SqlCommand portasDisponiveis = new SqlCommand();
        portasDisponiveis.CommandText = "DECLARE @idInterconect AS INT SET @idInterconect = '"+DDL_idInterconect.Text+"' SELECT M.NPortas-P.Qt Expr1 FROM Interconect I INNER JOIN Module M ON M.IdModule = I.IdModule CROSS APPLY (SELECT Count(1) Qt FROM Portas P WHERE P.IdInterconect = I.IdInterconect) P WHERE I.IdInterconect = @idInterconect";
        portasDisponiveis.Connection = con;

        con.Open();
        SqlDataReader dr = portasDisponiveis.ExecuteReader();
        while (dr.Read())
        {
            lbl_nPortasDisponiveis.Text = dr["Expr1"].ToString();
        }
        con.Close();

Obrigado a todos na mesma 🙂

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.