toptensoftware/PetaPoco — Issue #97: Exception when passing sqlParameter
Author: junkqwe
Created: 2012-01-14 11:24:06+00:00
State: open

when passing sqlParameter i get
The SqlParameter is already contained by another SqlParameterCollection
i solved it by changing AddParam function
i cnaged this
if (idbParam != null)
{
idbParam.ParameterName = string.Format("{0}{1}", ParameterPrefix, cmd.Parameters.Count);
cmd.Parameters.Add(idbParam);
return;
}

into this:
if (idbParam != null)
{
System.Data.SqlClient.SqlParameter param = (System.Data.SqlClient.SqlParameter)item;
System.Data.SqlClient.SqlParameter paramCopy = new System.Data.SqlClient.SqlParameter();
paramCopy.SqlDbType = param.SqlDbType;
paramCopy.Value = param.Value;
idbParam = paramCopy;
idbParam.ParameterName = string.Format("{0}{1}", ParameterPrefix, cmd.Parameters.Count);
cmd.Parameters.Add(idbParam);
return;
}