I want to convert DataRow To Object. I write 1 class to do this. Error like this:
No overload for method 'SetValue' takes 2 arguments
No overload for method 'GetValue' takes 1 arguments
But I can't using GetValues() and SetValues(). When converting project to 4.5. It's work. My project is set platform target is 3.5 (Obligatory - because I connect with the device must using .NET 3.5).
How to fix this?
Here my code:
public DataRowToObject(DataRow row)
{
List<PropertyInfo> listProperty = this.GetProperties();
foreach (PropertyInfo prop in listProperty)
{
if (!row.Table.Columns.Contains(prop.Name) ||
row[prop.Name] == null ||
row[prop.Name] == DBNull.Value)
{
prop.SetValue(this, null);
continue;
}
try
{
object value = Convert.ChangeType(row[prop.Name], prop.PropertyType);
prop.SetValue(this, value);
}
catch
{
prop.SetValue(this, null);
}
}
}
public virtual Hashtable GetParameters()
{
Type type = this.GetType();
List<PropertyInfo> listProperty = new List<PropertyInfo>(type.GetProperties());
Hashtable result = new Hashtable();
foreach (PropertyInfo prop in listProperty)
{
result.Add(prop.Name, prop.GetValue(this));
}
return result;
}