public DataTable ToDataTable(IList list) {
        DataTable dt = new DataTable();
     
        if (list.Count > 0) {
            foreach (IList ll in list) {
                for (int c = 0; c < ll.Count; c++) {
                    DataColumn dc = new DataColumn();
                    dc.DataType = System.Type.GetType("System.String");
                    dt.Columns.Add(dc);
                }
                break;
            }
          
            foreach (IList ll in list) {
                DataRow dr = dt.NewRow();
                for (int j = 0; j < ll.Count; j++) {
                    dr[j] = ll[j];
                }
                dt.Rows.Add(dr);
            }
        }
        return dt;
    }



这里只考虑全部是STRING类型,如果有其他类型,请用 反射 PropertyInfo[] propertys = list[0].GetType().GetProperties(); 获得原始类型!

相关文章:

  • 2021-12-27
  • 2022-12-23
  • 2021-07-07
  • 2022-02-13
  • 2021-11-16
  • 2021-12-21
  • 2021-08-12
  • 2021-06-03
猜你喜欢
  • 2021-05-25
  • 2021-10-31
  • 2022-02-27
  • 2021-08-06
  • 2021-07-28
相关资源
相似解决方案