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

来源:互联网 发布:《python算法教程 编辑:程序博客网 时间:2024/05/17 08:21

http://www.cnblogs.com/fuge/archive/2013/03/26/2981890.html

//循环去除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]);
            }
        }

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


原创粉丝点击