var curTable = dataSet.Tables[0];
RemoveEmpty(curTable);//调用方法
//清除datatable上的所有数据
protected void RemoveEmpty(DataTable dt)
{
List<DataRow> removelist = new List<DataRow>();
for (int i = 0; i < dt.Rows.Count; i++)
{
bool IsNull = true;
for (int j = 0; j < dt.Columns.Count; j++)
{
if (!string.IsNullOrEmpty(dt.Rows[i][j].ToString().Trim()))
{
IsNull = false;
}
}
if (IsNull)
{
removelist.Add(dt.Rows[i]);
}
}
for (int i = 0; i < removelist.Count; i++)
{
dt.Rows.Remove(removelist[i]);
}
}
清除datatable上的所有数据
最新推荐文章于 2026-03-29 04:38:50 发布
本文介绍了一种使用C#从DataTable中移除所有空行的有效方法。通过遍历每一行,检查其所有列是否为空,若整行为空,则将其添加到删除列表中,最后批量移除这些行,提高了数据清理的效率。

6717

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



