I have SQL parameter array as...
SqlParameter[] sqlParams = new SqlParameter[2];
If I want to add more parameters, Can I add to the current array ?
No you cannot append elements. In .NET arrays are static. If you want dynamic collections you could use a generic List<T> to which you could add elements dynamically.
var sqlParams = new List<SqlParameter>();
sqlParams.Add(param1);
sqlParams.Add(param2);
...
// convert to a static array if needed
SqlParameter[] result = sqlParams.ToArray();
sqlCommand.Parameters.AddRange(sqlParams.ToArray());Actually, I would just use the built in Parameters property of SqlCommand.
System.Data.SqlClient.SqlConnection connection
= new System.Data.SqlClient.SqlConnection("connection string goes here");
System.Data.SqlClient.SqlCommand command = connection.CreateCommand();
System.Data.SqlClient.SqlParameter parameter = command.CreateParameter();
parameter.ParameterName = "@ParameterName";
parameter.DbType = DbType.String;
parameter.Value = "Some String Value";
command.Parameters.Add(parameter);
Then later, if you need to access them, you can do so by:
SqlParameter param = command.Parameters[0];
That way you don't have to mess with adding a range and keeping track of a separate array or List<>.