阿里云折扣码

轻云博客 > C#技术 > c# 删除 DataTable 里面空行的算法

c# 删除 DataTable 里面空行的算法

作者:Aisencici / 日期:2015-6-3 17:08:00 / 分类:C#技术 / 浏览:3572

//循环去除datatable中的空行
        protected void 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]);
            }
        }

本文标签:
From:
分享到: