Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
Laiju k 3-Nov-14 23:02pm    
How many tables your dataset contains
shiva2838 3-Nov-14 23:28pm    
Three tables..
Laiju k 3-Nov-14 23:32pm    
Have you tried the below solution
syed shanu 3-Nov-14 23:13pm    
One way is you need to select all bottom lines of excel and delete
syed shanu 3-Nov-14 23:18pm    
Chk this link,
Same question has been asked here hope this will solve you.
https://social.msdn.microsoft.com/Forums/en-US/0385aa4a-1db2-41e6-8431-f0a2835ae317/removing-empty-rows-from-dataset?forum=adodotnetdataproviders

Hi,

For each table in your dataset, try the following code:
C#
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();



Hope this works for you :)

Regards,
Praneet
 
Share this answer
 
Comments
shiva2838 4-Nov-14 2:40am    
Thanks for it,I tried the above solution , It doesnt work for me .... its looping correctly but its not removing empty rows..But this solution has provided me an idea, I have posted my solution below that is working
Linq Query has solved my problem.

C#
dt.Rows.Cast<DataRow>().Where(rows+>!row.ItemArray.all(field =>field is System.DBNull || String.compare((field as String.Trim(),String.Empty)==0)).CopytoDatatable();
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900