.net - Can I add a Parametercollection to another Parametercollection? -


the sqlparametercollection has add(sqlparameter) method, , addrange(sqlparameter[]) method. each has several overloads.

specifically, sqlcommand.parameters read only, , if have sqlparametercollection can't assign it, want add onto existing collection.

right there's loop in code:

sqlcommand cmd = new sqlcommand(); foreach (sqlparameter param in collection) {     cmd.parameters.add(param); } 

is there easy built-in way add sqlparametercollection another?

i've set extension method make procedure easier. haven't found 'real' way, however:

(edited re suggestion @danielpaoliello)

public static void addcollection(this sqlparametercollection basic, sqlparametercollection collection) {     foreach (sqlparameter param in collection)     {         basic.add(((param icloneable).clone()) sqlparameter);     } } 

than use as:

cmd.parameters.addcollection(collection); 

Comments