如何删除DataTable中的空行/空行? [英] How to Remove Blank/Empty Rows in DataTable?

查看:721
本文介绍了如何删除DataTable中的空行/空行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在数据表中删除空行或空行。

我的代码段



I want to Delete the Empty rows or Blank Rows in Datatable.
My Snippet

public void deleteemptyrows(DataTable dt)
   {
       for (int i = dt.Rows.Count; i >= 1; i--)
       {
           DataRow currentRow = dt.Rows[i - 1];
           foreach (var col in currentRow.ItemArray)
           {
               if (!string.IsNullOrEmpty(col.ToString()))
                   break;

               dt.Rows[i - 1].Delete();
           }
       }
   }



但它不起作用

请帮我


But it is not working
pls Help Me

推荐答案

使用调试器逐步查看代码,以确切了解每个阶段发生的情况。并且说它不起作用,对我们来说真的没有任何意义;我们无法看到发生了什么。
Use your debugger to step through the code to see exactly what is happening at each stage. And saying "it is not working", really means nothing to us; we cannot see what is happening.


在你的查询中不要选择有空值的行。

例如。
In your query Dont select the row where there is null value.
eg.
select * from Your_table where columnName !=null



然后用这个查询填充数据表。


and then fill the datatable with this query.


这篇关于如何删除DataTable中的空行/空行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆