Link to home
Start Free TrialLog in
Avatar of aspnetdev
aspnetdev

asked on

Closing SQL connection after return statement

Hi i have a following method
Public Function Bind() As DataSet
     Dim sqlConn As SqlConnection = New SqlConnection(CManager.AppSettings("ConnectionString"))
     Dim adapter As SqlDataAdapter = New SqlDataAdapter("Get", sqlConn)
     Dim ds As New DataSet("ds")

     adapter.SelectCommand.CommandType = CommandType.StoredProcedure
     adapter.Fill(ds)

     Return ds

     adapter.Dispose()
     sqlConn.Close()
End Function

i am closing the sql connection and disposing the dataadapter after teh RETURN statement,will any statement after return execute ...?can any one tell me whats the best approach to go about it.
Thanks
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sudheeshthegreat
sudheeshthegreat

burakiewiczDate: that's true for C#. But, if you notice the code snippet that aspnetdev shows is in VB.Net :-)
didnt check that close, its in the C# section so i figured it was C#, but the using statement is also available in VB
'using' in vb.net? that's cool. wasnt there when i last checked.
yeah its there in VS2005
heres a link from msdn. not a great one though
http://msdn2.microsoft.com/en-us/library/htd05whh(VS.80).aspx