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 ?

1 Like

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)

1 Like

@SantoshPothina PFB


Hi, How to check particular column is null or empty, If column is not empty. Then how to get that value present in column. Please provide solution for this?
Thanks in Advance

How to check datatable is null or zero rows .we need to exclude two columns as they have values in it.
Any suggestions please
@vvaidya @Bharat_Kumar @Palaniyappan @NIVED_NAMBIAR @lakshman @ClaytonM


Try below expression.

                  outputDT = InputDT.DefaultView.ToTable(False,"Column 1","Column 2",...."Column N")

Mention all columns except those 2 columns which contains values. And then check Rows count as below.

              IF outputDT.Rows.Count > 0
                    Rows exists
                     Rows doesn't exists
1 Like

This expression still giving me count…is it instead of fals…do we have to type true in expression in my case


Write OutputDT into Excel file using Write Range activity and check what data it is giving as output.

1 Like