#region 封装DataTable
DataTable dt = null;
if (newRows.Length > 0)
{
dt = newRows[0].Table.Clone(); // 复制DataRow的表结构
foreach (DataRow row in rows)
{
dt.Rows.Add(row.ItemArray); // 将DataRow添加到DataTable中
}
}
#endregion
本文介绍了一种使用C#在ASP.NET项目中将DataRow集合封装为DataTable的方法。通过克隆原始DataRow的表结构并逐条添加数据,可以高效地完成转换过程。
#region 封装DataTable
DataTable dt = null;
if (newRows.Length > 0)
{
dt = newRows[0].Table.Clone(); // 复制DataRow的表结构
foreach (DataRow row in rows)
{
dt.Rows.Add(row.ItemArray); // 将DataRow添加到DataTable中
}
}
#endregion
4660

被折叠的 条评论
为什么被折叠?