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.App Settings(" Connection String"))
Dim adapter As SqlDataAdapter = New SqlDataAdapter("Get", sqlConn)
Dim ds As New DataSet("ds")
adapter.SelectCommand.Comm andType = CommandType.StoredProcedur e
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
Public Function Bind() As DataSet
Dim sqlConn As SqlConnection = New SqlConnection(CManager.App
Dim adapter As SqlDataAdapter = New SqlDataAdapter("Get", sqlConn)
Dim ds As New DataSet("ds")
adapter.SelectCommand.Comm
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
heres a link from msdn. not a great one though
http://msdn2.microsoft.com/en-us/library/htd05whh(VS.80).aspx