private photo getPhoto(DataRow dr) { photo w = new photo(); Type source = dr.GetType(); Type dest = w.GetType(); foreach (PropertyInfo pi in dest.GetProperties()) { if (dr.Table.Columns.Contains(pi.Name)) { string str = dr[pi.Name].ToString(); if (pi.PropertyType == typeof(bool)) { bool bout = false; bool.TryParse(str, out bout); pi.SetValue(w, bout); } else if (pi.PropertyType == typeof(double)) { double bout = 0; double.TryParse(str, out bout); pi.SetValue(w, bout); } else if (pi.PropertyType == typeof(DateTime)) { DateTime bout = DateTime.MinValue; DateTime.TryParse(str, out bout); pi.SetValue(w, bout); } else if (pi.PropertyType == typeof(Int32)) { Int32 bout = Int32.MinValue; Int32.TryParse(str, out bout); pi.SetValue(w, bout); } else pi.SetValue(w, str); } } return w; }