• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 698
  • Last Modified:

dim vs using

Is there a different in performance in these two subs? Would you choose one over the other?


1.


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")
                        Me.ListView1.DataBind()


                    End Using
                End Using

            End Using

        End Using
    End Sub


2.  

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")
                        Me.ListView1.DataBind()



         
    End Sub
0
VBdotnet2005
Asked:
VBdotnet2005
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
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).
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now