DataTable dt = new DataTable();
_EvaluateModel ee = new _EvaluateModel();
try
{
Type cctype = ee.GetType();
foreach (PropertyInfo pi in cctype.GetProperties())
{
string Name = "";
Name = pi.Name;
if (!string.IsNullOrEmpty(Name))
{
dt.Columns.Add(Name, pi.PropertyType);
}
}
if (dt.Columns.Count > 0)
{
for (int i = 0; i < mylist.Count; i++)
{
_EvaluateModel Item = mylist[i];
DataRow row = dt.NewRow();
Type type = Item.GetType();
foreach (PropertyInfo info in type.GetProperties())
{
row[info.Name] = info.GetValue(Item, null);
}
dt.Rows.Add(row);
}
}
}
catch (Exception ex) { }
return dt;
类转化为datatable
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
CSharpCodeProvider 类
Syron_lee
2018-08-23 14:11:04
C# 内在管理与指针日记
Syron_lee
2018-08-23 14:11:03
未能加载文件或程序集“CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0
Syron_lee
2018-08-23 14:11:03
获取客户端的IP地址
Syron_lee
2018-08-23 14:11:02
使用 GetOleDbSchemaTable 和 Visual C# .NET 检索架构信息
Syron_lee
2018-08-23 14:11:02
Many to Many relation with Entity Framework
Syron_lee
2018-08-23 14:11:02
C# 读excel 方法
Syron_lee
2018-08-23 14:10:23