1
나는 목록 내가이 가능 table.How 데이터에이를 변환 할변환하는 방법 <KeyValuePair <string, decimal >> list = 새 목록 <KeyValuePair <string, decimal >>(); DataTable에?
List<> list = new List<>();
있나요? 다음
는나는 목록 내가이 가능 table.How 데이터에이를 변환 할변환하는 방법 <KeyValuePair <string, decimal >> list = 새 목록 <KeyValuePair <string, decimal >>(); DataTable에?
List<> list = new List<>();
있나요? 다음
는
public DataTable ConvertToDataTable<T>(IList<T> data)
{
PropertyDescriptorCollection properties =
TypeDescriptor.GetProperties(typeof(T));
DataTable table = new DataTable();
foreach (PropertyDescriptor prop in properties)
table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
foreach (T item in data)
{
DataRow row = table.NewRow();
foreach (PropertyDescriptor prop in properties)
row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
table.Rows.Add(row);
}
return table;
}
의 중복 가능성 [DataTable을에 Enumerable에서 일반적인 목록을 변환 /?] (.. 당신은 데이터 테이블에있는 목록 개체를 변환 할 수있는 방법입니다 http://stackoverflow.com/questions/564366/convert-generic-list-enumerable-to-datatable) –