#region 把DataRow转化成对象
/// <summary>
/// 把DataRow转化成对象
/// </summary>
/// <param name="dr">dr</param>
/// <param name="obj">对象</param>
/// <returns></returns>
public static object DataRowToObj(System.Data.DataRow dr, object obj)
{
try
{
if (dr != null && obj != null)
{
Type t = obj.GetType();
PropertyInfo[] f = t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
string tableName = t.Name;
foreach (PropertyInfo pi in f)
{
string field = pi.Name;
if (dr.Table.Columns.Contains(field) && dr[field] != DBNull.Value)
pi.SetValue(obj, dr[field], null);
}
}
}
catch (Exception ex)
{
new Exception(ex.ToString());
return null;
}
return obj;
}
#endregion