Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

I am using VS 2012, C# and ASP.NET

I have a Dataset, in which I am trying to delete the empty rows.

How to achieve this?
Posted
Comments
DamithSL 14-Jun-14 2:20am    
can't you select only the not empty rows when you create dataset?

1 solution

try this.. :)

C#
DataSet ds = new DataSet();

               for (int i = 0; i < ds.Tables.Count; i++)
               {
                     for (int j = 0; j < ds.Tables[i].Rows.Count; j++)
                   {
                       if (Convert.ToString(ds.Tables[i].Rows[j]["ColumnName"]) == string.Empty)
                       {
                           ds.Tables[i].Rows[j].Delete();

                       }
                   }

               }


i have created this snippet without testing of it, so modify it according to your need.
 
Share this answer
 
v3
Comments
HardikPatel.SE 14-Jun-14 2:08am    
5+
Nirav Prabtani 14-Jun-14 2:08am    
thanks.. :)
Instead of comparing with "", compare with string.Empty always.
Nirav Prabtani 14-Jun-14 2:24am    
Thanks ,i have updated it.
Good. :)

My 5+.

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