How to delete the whole column in DataTable if the header is not empty , but the column is?



So I have a datatable with headers in the first row. Could someone please help me with code snippet or something that can help deleting whole column If the values are empty.(headers are not empty, only the column below it)
I have only found how to delete row on this forum but not column.

EDIT: Idk, guys, I tried everything and it didnt work for me. Im not sure what is the problem :frowning:


Hi @4head ,

1.Declare int Variable intCount
2.Using Assign activity intCount=dt.Select(β€œName is not Null or Name <> β€˜β€™β€).ToList().Count()
3. Keep If activity with condition intCount<=0 then true
4.Remove data column Activity




First Declare a List of strings ListA
Let us take you have a datatable dta

Niow we will take the array of column headers where the entire column is not empty

ListA=(From p in dt.Columns.CastOf(System.Data.DataColumn)
           where( From q in dt.Select
                      where not string.IsNullOrEmpty(q(p.ColumnName).ToString)
                      Select q).Count>0
          Select Convert.ToString(p.ColumnName)).ToList

Now List A will have the Column Names where the columns have values.

Now Let us declare a new datatable dtb

dtb= dta.DefaultView.ToTable(False,ListA.ToArray)

Now Datatable dtb will contain the columns which have the values.



Hi @4head
Please check this.
DeleteEmptyColumnsInDT.xaml (17.9 KB)

just a basic level flow and it is working :smiley:

Best Regards,