Dispose warnings on SqlAdapter code

I am rewriting a .NET 1.1 app to 4.0.  This code compiles just fine, but I receive numerous warnings  like:
"call System.IDispoable.Dispose on object 'sqlCmd' before all references to it are out of scope".
I also get that warning for da and results.
Is it really important that I clean that up?  And how would I "dispose" of these?  I thought the garbage collector does that for me.  
Thank you for helping!
    Public Function SelectTsql(ByVal qryString As String) As DataTable
        Dim sqlCmd As SqlCommand

        Dim da As SqlDataAdapter
        Dim results As DataTable

        sqlCmd = New SqlCommand

        With sqlCmd
            '.Transaction = transaction
            .CommandTimeout = 240
            .CommandText = qryString
            If _sqlInSrvCnn1.State = ConnectionState.Open Then
                .Connection = _sqlInSrvCnn1
                .Connection = _sqlInSrvCnn2
            End If
            .CommandType = CommandType.Text
            da = New SqlDataAdapter(sqlCmd)
            results = New DataTable
        End With

        If results.Rows.Count > 0 Then
            Return results
            Return Nothing
        End If

    End Function

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
The DataAdapter and SqlCommand objects both inherit a Dispose() method, which you should call to release the non-managed resources used by the object.

It is good practice to clean up after yourself. The garbage collector will do it for you - eventually - but you should do it yourself too. Simple rule: if the object supports Dispose(), you should call it when you're done with the object.

A good habit to get into would be using a "Using" statement to wrap any database objects. That way they will automatically be disposed when they fall out of scope: http://msdn.microsoft.com/en-us/library/htd05whh.aspx

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ToolTimeGangAuthor Commented:
Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.