Can I do:
using connection
myDt1 = sqlSelect(connection, sql)
myDt2 = sqlSelect(connection, sql)
end using
with SQLSelect :
Public Shared Function SQLSelect(ByVal provider As SqlConnection, ByVal strSQL As String, ByVal ParamArray params() As SqlParameter) As DataTable
Using connection = provider
SQLSelect = New DataTable
Dim dtReader As SqlDataReader
Dim command As SqlCommand = CreateSQLCommand(provider, strSQL, params)
Try
connection.Open()
dtReader = command.ExecuteReader()
SQLSelect.Load(dtReader)
dtReader.Close()
Catch ex As Exception
SQLSelect = Nothing
Finally
'If connection.State = ConnectionState.Open Then
' connection.Close()
'End If
command.Dispose()
End Try
End Using '<--- Here drop connection
Return SQLSelect
Because in the SQLSelect function, at the end of the using, the connection is broken! So I have an error when I try to connect to the second query.
Thx
Simply use a DAL pattern like this:
...
Calling code: