DataTable dt = new DataTable();
DataRow dr = dt.Rows[0];
PropertyInfo[] properties= dr.GetType().GetProperties();
properties[0].GetValue(dr, null);
这个不管用吗?
楼主应该是想要
dt.rows[i]["ID"]这样的数据吗?
如果是的话,可以同时遍历列和行就可以取得数据了.
System.Data.DataTable dt = new System.Data.DataTable();
foreach (System.Data.DataColumn col in dt.Columns){
foreach (System.Data.DataRow row in dt.Rows) { Response.Write(row[col.ColumnName]);
}
}
public static DataTable ToDataTable(IList<T> list)
{
DataTable result = new DataTable();
if (list.Count > 0)
{
System.Reflection.PropertyInfo[] propertys = list[0].GetType().GetProperties();
foreach (System.Reflection.PropertyInfo pi in propertys)
{
result.Columns.Add(pi.Name, pi.PropertyType);
}
for (int i = 0; i < list.Count; i++)
{
ArrayList tempList = new ArrayList();
foreach (System.Reflection.PropertyInfo pi in propertys)
{
object obj = pi.GetValue(list[i], null);
tempList.Add(obj);
}
object[] array = tempList.ToArray();
result.LoadDataRow(array, true);
}
}
return result;
}