如何在数据集中删除底部的空/空行 [英] How Do I Delete Empty/Blank Rows At Bottom In A Dataset
本文介绍了如何在数据集中删除底部的空/空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个Windows应用程序,其中将Excel数据加载到数据网格视图中,我使用oledb连接将整个Excel数据加载到数据集,但是底部有一些空/空行也加载到数据集中,有没有办法删除那些空白行。
I am developing an windows application where excel data is loaded into an data grid view, i am using oledb connection to load entire excel data to dataset, but there are some empty/blank rows at bottom which is also loaded into dataset,Is there any way to delete that blank rows.
推荐答案
对于你的每张表数据集,请尝试以下代码:
Hi,
For each table in your dataset, try the following code:
string valuesarr = string.Empty;
for (int i = 0; i < dt.Rows.Count - 1; i++)
{
List<object> lst = dt.Rows[i].ItemArray.ToList();
foreach (Object s in lst)
{
valuesarr += s.ToString();
}
if (String.IsNullOrEmpty(valuesarr))
dt.Rows.RemoveAt(i);
}
dt.AcceptChanges();
希望这适用于你:)
问候,
Praneet
Hope this works for you :)
Regards,
Praneet
试试这个。
http:// stackoverflow。 com / questions / 17464668 / delete-rows-that-contains-null-value-from-datatable [ ^ ]
Linq Query解决了我的问题。
Linq Query has solved my problem.
dt.Rows.Cast<DataRow>().Where(rows+>!row.ItemArray.all(field =>field is System.DBNull || String.compare((field as String.Trim(),String.Empty)==0)).CopytoDatatable();
这篇关于如何在数据集中删除底部的空/空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文