Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SqlParameterCollection.CopyTo errors out on null

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
0
0
US
I have a Stored procedure that returns parameters of a given stored procedure.

I then want to pass back an SqlParameter[] but in my procedure I defined the array as:

SqlParameter[] parameters = null.

This causes the CopyTo method to give me an error:

Code:
        public static SqlParameter[] GetProcedureParameters(string procedureName)
        {
            SqlConnection myConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
            SqlCommand myCommand = new SqlCommand();
            myCommand.Connection = myConnection;
            myCommand.CommandText = procedureName;
            myCommand.CommandType = CommandType.StoredProcedure;
            SqlParameter[] parameters = null;

            myConnection.Open();
            SqlCommandBuilder.DeriveParameters(myCommand);
            myConnection.Close();
            myCommand.Parameters.CopyTo(parameters, 0);
            return parameters;
        }

I get the error:

Value cannot be null.
Parameter name: dest

myCommand has 3 parameters but it can't copy them to parameters object.

How do I get around this?

Thanks,

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top