How do you copy DbCommand
parameters to another DbCommand
, I want a new DbCommand
with the same parameters as my last DbCommand
. But now with a different sql string.
You could put the code you need to re-use in a separate method:
public DbCommand RecycledParameters(string sql, IList<DbParameter> parameters)
{
var result = db.GetSqlStringCommand(sql);
foreach(DbParameter p in parameters)
{
db.AddInParameter(result, p.ParameterName, p.DbType, p.Value);
}
return result;
}