0 votes
by (120 points)
edited

I have a problem regarding this code how to assign parameter every time i assign parameter It gives error like null value or refrence connection please help me how I assigh parameters like connection command adn my code is

my code here:

private static void PrepareCommand(SqlCommand command, SqlConnection connection,

                              SqlTransaction transaction, CommandType commandType,                       string commandText, SqlParameter[] 


                      commandParameters, out bool mustCloseConnection )

{ if( command == null ) throw new ArgumentNullException( "command" ); if( commandText == null || commandText.Length == 0 ) throw new ArgumentNullException( "commandText" );

        // If the provided connection is not open, we will open it
        if (connection.State != ConnectionState.Open)
        {
            mustCloseConnection = true;
            connection.Open();
        }
        else
        {
            mustCloseConnection = false;
        }

        // 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 (transaction != null)
        {
            if( transaction.Connection == null ) throw new ArgumentException( "The transaction was rollbacked or commited, please provide an open transaction.", "transaction" );
            command.Transaction = transaction;
        }

        // Set the command type
        command.CommandType = commandType;

        // Attach the command parameters if they are provided
        if (commandParameters != null)
        {
            AttachParameters(command, commandParameters);
        }
        return;
    }

1 Answer

0 votes
by (148k points)
edited

Hello,

This is a Q&A forum dedicated to Rebex components, not a general-purpose .NET forum. We only answer questions related to Rebex components, sorry! Try posting your question to a general-purpose programming Q&A forum such as Stack Overflow.

...