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
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.
ListA=(From p in dt.Columns.Cast( Of 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