This method opens (if necessary) and assigns a connection, transaction, command type and parameters
to the provided command.
Parameters:
-command - the SqlCommand to be prepared
-connection - a valid SqlConnection, on which to execute this command
-transaction - a valid SqlTransaction, or null
-commandType - the CommandType (stored procedure, text, etc.)
-commandText - the stored procedure name or T-SQL command
-commandParameters - an array of SqlParameters to be associated with the command or null if no parameters are required
Private Shared Sub PrepareCommand(ByVal command As SqlCommand, _
ByVal connection As SqlConnection, _
ByVal transaction As SqlTransaction, _
ByVal commandType As CommandType, _
ByVal commandText As String, _
ByVal commandParameters() As SqlParameter)
if the provided connection is not open, we will open it
If connection.State <> ConnectionState.Open Then
connection.Open()
End If
associate the connection with the command
command.Connection = connection
set the command text (stored procedure name or SQL statement)
command.CommandText = commandText
if we were provided a transaction, assign it.
If Not (transaction Is Nothing) Then
command.Transaction = transaction
End If
set the command type
command.CommandType = commandType
attach the command parameters if they are provided
If Not (commandParameters Is Nothing) Then
AttachParameters(command, commandParameters)
End If
Return
End Sub PrepareCommand