/// <summary>
/// 实现对IList到DataSet的转换
/// </summary>
/// <param name="list">待转换的IList</param>
/// <returns>转换后的DataSet</returns>
public static DataSet IListToDataSet<T>(IList<T> list, Type type)
{
if (list == null || list.Count <= 0)
{
return null;
}
DataSet ds = new DataSet();
DataTable dt = new DataTable(type.Name);
DataColumn column;
DataRow row;
System.Reflection.PropertyInfo[] myPropertyInfo = type.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
foreach (T t in list)
{
if (t == null)
{
continue;
}
row = dt.NewRow();
for (int i = 0, j = myPropertyInfo.Length; i < j; i++)
{
System.Reflection.PropertyInfo pi = myPropertyInfo[i];
string name = pi.Name;
if (dt.Columns[name] == null)
{
column = new DataColumn(name, pi.PropertyType);
dt.Columns.Add(column);
}
row[name] = ((object[])(object)t)[i] == null ? DBNull.Value : ((object[])(object)t)[i];
}
dt.Rows.Add(row);
}
ds.Tables.Add(dt);
return ds;
}
DataSet ds;
Type type = typeof(GetWageByDtTwo_Brand);
ds = PageText.IListToDataSet<Object[]>(data, type);