var ddd = Nullable.GetUnderlyingType(typeof(int?));
DataTable dt = new DataTable();
Quot_Part_Model one = new Quot_Part_Model();
one.Part_Name = "AAA";
var properties = one.GetType().GetProperties();
foreach (var read in properties)
{
var underlyingType = Nullable.GetUnderlyingType(read.PropertyType);
if (underlyingType != null)
dt.Columns.Add(read.Name, underlyingType);
else
dt.Columns.Add(read.Name, read.PropertyType);
if (dt.Columns.Count <= 1)
dt.Rows.Add();
dt.Rows[0][read.Name] = read.GetValue(one, null) == null ? DBNull.Value : read.GetValue(one, null);
}
var row = dt.Rows[0];
row["User_ID"] = "97";
row["Part_Name"] = "BBBB";
row["Control_Visible"] = 111;
row["Process_List"] = "sdsd";
row["Create_Date"] = DateTime.Now;
foreach (var read in properties)
{
if (row[read.Name] is DBNull)
read.SetValue(one, null, null);
else
read.SetValue(one, row[read.Name], null);
}
}