How to check if a particular column is empty in DataTable (Without using For Each Row)?



Without using For Each Row loop, How can we check if a column is empty or not in DataTable ??
I want to delete a column if it is empty and I acheived it with the help of For Each loop. Can anyone help me in solving this without loop?


In If Condition Check
DataTable.Rows(0)(“columnname”) is DBNull.Value then Delete a column


for each column in dt
if dt.Select(dt.Columns(index or columnname)=dbnull).Length=dt.Rows.Count
then msgbox “column is empty”
end if


@KinjalRD @Atrimal Thank you! I already tried this way but not worked.

error : DBNull is a type and cannot be used as an expression.

Can you please check again?



Hi Santhosh,

You can try this out.


Check if,

DataTable.Rows(0)(“columnname”).ToString = “”


dt.Select(dt.Columns(index or columnname).tostring="").Length=dt.Rows.Count


@RupeshGonte Thank you!

DataTable.Rows(0)(“columnname”).ToString = ""
this will check only for the first row , I need it for whole data table without using any loop. can you try ?


You can try using below linq query
(From row In dt where row(“id”) isnot DBNull.Value).CopyToDatatable

Or You can assign it to array of DataRow

datarow[] arr = (From row In dt where row(“id”) isnot DBNull.Value).toArray
and check
if( arr.count=0)


@SantoshPothina PFB