G
Guest
I'm trying to iterate stored parameters and populate any public properties of
an object with the parameter value. I've suceeded in doing it the other way
around, but when I try it to the object I keep getting the error "Object does
not match target type".
I've tried field.SetValue(p, p.Value, BindingFlags.SetField, null, null,
null) and a couple variations without sucess.
Thanks in advance for any help you can offer.
public static void PopulateRecordFromProcedureParameters(Object Record,
SqlCommand cmd)
{
PropertyInfo field = null;
foreach (SqlParameter p in cmd.Parameters)
{
if (p.Direction != ParameterDirection.Input)
{
field =
Record.GetType().GetProperty(p.ParameterName.Replace("@", ""));
// Here's where I need to set the value
field.SetValue(p, p.Value, BindingFlags.SetField, null, null, null);
}
}
} // PopulateRecordFromProcedureParameters
an object with the parameter value. I've suceeded in doing it the other way
around, but when I try it to the object I keep getting the error "Object does
not match target type".
I've tried field.SetValue(p, p.Value, BindingFlags.SetField, null, null,
null) and a couple variations without sucess.
Thanks in advance for any help you can offer.
public static void PopulateRecordFromProcedureParameters(Object Record,
SqlCommand cmd)
{
PropertyInfo field = null;
foreach (SqlParameter p in cmd.Parameters)
{
if (p.Direction != ParameterDirection.Input)
{
field =
Record.GetType().GetProperty(p.ParameterName.Replace("@", ""));
// Here's where I need to set the value
field.SetValue(p, p.Value, BindingFlags.SetField, null, null, null);
}
}
} // PopulateRecordFromProcedureParameters