DataTable dt = new DataTable();
if (_list != null)
{
//通过反射获取list中的字段
System.Reflection.PropertyInfo[] p = _list[].GetType().GetProperties();
foreach (System.Reflection.PropertyInfo pi in p)
{
dt.Columns.Add(pi.Name, System.Type.GetType(pi.PropertyType.ToString()));
}
for (int i = ; i < _list.Count; i++)
{
IList TempList = new ArrayList();
//将IList中的一条记录写入ArrayList
foreach (System.Reflection.PropertyInfo pi in p)
{
object oo = pi.GetValue(_list[i], null);
TempList.Add(oo);
}
object[] itm = new object[p.Length];
for (int j = ; j < TempList.Count; j++)
{
itm.SetValue(TempList[j], j);
}
dt.LoadDataRow(itm, true);
}
}