dim vs using

Posted on 2009-04-16
Last Modified: 2012-05-06
Is there a different in performance in these two subs? Would you choose one over the other?


Public Sub ViewData()

        Using Con As New SqlConnection(WebConfigurationManager.ConnectionStrings("myConnectionString").ToString)
            Using Cmnd As New SqlCommand("select *from mytable", Con)
                Using AD As New SqlDataAdapter(Cmnd)
                    Using DS As New DataSet

                        AD.Fill(DS, "table1")

                        Me.ListView1.DataSource = DS.Tables("table1")

                    End Using
                End Using

            End Using

        End Using
    End Sub


Public Sub ViewData()

        dim Con As New SqlConnection(WebConfigurationManager.ConnectionStrings("myConnectionString").ToString)
        dim Cmnd As New SqlCommand("select *from mytable", Con)
        dim AD As New SqlDataAdapter(Cmnd)
        dim DS As New DataSet

                        AD.Fill(DS, "table1")

                        Me.ListView1.DataSource = DS.Tables("table1")

    End Sub
Question by:VBdotnet2005
    1 Comment
    LVL 69

    Accepted Solution

    the biggest advantage is that your first snippet will call the Dispose method of each object on the End Using and this help freeing resources (which in turn can help performance on the long run).

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now