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