Leonardo_Augusto Posted April 8, 2015 at 04:28 PM Report Share #580919 Posted April 8, 2015 at 04:28 PM (edited) Olá tenho as duas SUB() abaixo, mas como a finalidade das duas é similar, gostaria de uma dica para otimizar, talvez reunir tudo em uma consulta apenas Sub Valores() Dim cmd As New SqlCommand("select * from Numeros", Conexao.Conectar) Dim dr As SqlDataReader Try dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection) While dr.Read() Label1.Text = dr("Artigos") Label2.Text = dr("Sistemas") Label4.Text = dr("Projetos") End While Catch ex As Exception dr = Nothing Throw ex Finally End Try End Sub Sub ContaUser() Dim cmd As New SqlCommand("select count(*) AS UserId from Users", Conexao.Conectar) Dim dr As SqlDataReader Try dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection) While dr.Read() Label3.Text = dr("UserId") End While Catch ex As Exception dr = Nothing Throw ex Finally End Try End Sub Edited April 8, 2015 at 05:20 PM by apocsantos geshi Link to comment Share on other sites More sharing options...
Solution nelsonr Posted April 9, 2015 at 08:31 AM Solution Report Share #580940 Posted April 9, 2015 at 08:31 AM Boas, então porque não juntas as duas numa só? Fazes uma operação e de seguida a outra. Não te esqueças de fechar os readers. Se precisas de ler apenas um registo não uses o While, faz apenas If (o while vai passar por todas os resultados do comando) 1 Report Link to comment Share on other sites More sharing options...
Leonardo_Augusto Posted April 11, 2015 at 10:53 PM Author Report Share #581071 Posted April 11, 2015 at 10:53 PM Obrigado ,ótima dica! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now