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:
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
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