C#对象转dataTable 示例代码
private DataTable CreateTableBySignCitizenViewModel(List<SignCitizenViewModel> list)
{
try
{
var dt = new DataTable();
var array = new List<string>() { "QYZT", "JYTD" };
array.ForEach(_ => dt.Columns.Add(_));
foreach (var m in list)
{
var row = dt.NewRow();
dt.Rows.Add(row);
row["QYZT"] = m.QYZT;
row["JYTD"] = m.JYTD;
}
return dt;
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
return null;
}