/// <summary> /// 把泛型转换成DataTable /// </summary> /// <param name="layerTable">泛型集合</param> /// <returns></returns> private DataTable ListConvertDataTable(List<LayerTable> layerList) { DataTable dt = new DataTable(); dt.Columns.Add("PrimaryKey"); dt.Columns.Add("LayerName"); dt.Columns.Add("FatherID"); try { LayerTable layerTable = new LayerTable(); if (layerList != null || layerList.Count > 0) { for (int i = 0; i < layerList.Count; i++) { layerTable = layerList[i]; DataRow dr = dt.NewRow(); dr["PrimaryKey"] = layerTable.PrimaryKey; dr["LayerName"] = layerTable.LayerName; dr["FatherID"] = layerTable.FatherID; dt.Rows.Add(dr); } } } catch (Exception e) { MessageBox.Show(e.Message); } return dt; }
把list转换成 datatable
最新推荐文章于 2023-01-04 18:56:50 发布