csharp Remove Empty rows in datatable

 1 //20120803 Geovin Du
 2                 //塗聚文 締友計算機信息技術有限公司
 3                 DataTable dt = new DataTable();
 4                 dt=agreementMonthlySalaryListBLL.SelectImportExceltoDataGridView(fileUrl, sheet).Copy();
 5 
 6                 if ((dt != null) && (dt.Rows != null) && (dt.Rows.Count > 0))
 7                 {
 8                     List<System.Data.DataRow> removeRowIndex = new List<System.Data.DataRow>();
 9                     int RowCounter = 0;
10                     foreach (System.Data.DataRow dRow in dt.Rows)
11                     {
12                         for (int index = 0; index < dt.Columns.Count; index++)
13                         {
14                             if (dRow[index] == DBNull.Value)
15                             {
16                                 removeRowIndex.Add(dRow);
17                                 break;
18                             }
19                             else if (string.IsNullOrEmpty(dRow[index].ToString().Trim()))
20                             {
21                                 removeRowIndex.Add(dRow);
22                                 break;
23                             }
24                         }
25                         RowCounter++;
26                     }
27                     // Remove all blank of in-valid rows
28                     foreach (System.Data.DataRow rowIndex in removeRowIndex)
29                     {
30                         dt.Rows.Remove(rowIndex);
31                     }
32                 }
33                 dataGridView1.DataSource = null;
34                 set.SetDataGridViewBindingSourceNavigatorBinds(dataGridView1,dt , bindingSource1, bindingNavigator1);
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)成功.---Geovin Du(涂聚文)
原文地址:https://www.cnblogs.com/geovindu/p/2620522.html