美文网首页
DataTable移除空行

DataTable移除空行

作者: 朱冬杰 | 来源:发表于2020-08-27 18:22 被阅读0次

protected DataTable RemoveEmpty(DataTable dt)

{

    List<DataRow> removelist = new List<DataRow>();

    for (int i = 0; i < dt.Rows.Count; i++) 

     {

                bool rowdataisnull = true;

                for (int j = 0; j < dt.Columns.Count; j++)

                {

                    if (!string.IsNullOrEmpty(dt.Rows[i][j].ToString().Trim()))

                    {

                        rowdataisnull = false;

                    }

                }

                if (rowdataisnull)

                {

                    removelist.Add(dt.Rows[i]);

                }

            }

            //移除空行

    for (int i = 0; i < removelist.Count; i++)

   {

        dt.Rows.Remove(removelist[i]);

    }

    return dt;

}

相关文章

网友评论

      本文标题:DataTable移除空行

      本文链接:https://www.haomeiwen.com/subject/bpkhsktx.html