Jump to content

Otimizar consulta SQL


Leonardo_Augusto
 Share

Go to solution Solved by nelsonr,

Recommended Posts

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 by apocsantos
geshi
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.