list泛型转换成DataTable
1个回答
展开全部
/// <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;
}
/// 把泛型转换成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;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询