Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to Delete the Empty rows or Blank Rows in Datatable.
My Snippet

C#
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
Posted

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.
 
Share this answer
 
In your query Dont select the row where there is null value.
eg.
SQL
select * from Your_table where columnName !=null

and then fill the datatable with this query.
 
Share this answer
 

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