How to check if a data table column contains any values?

Hi all,

How do I check if a data table column contains any values?

1 Like

Scenario
1.Use Foreachrow activities.
2.Iterate thru foreachrow and use if condition activites.
3.row(“Columname”).Tostring ="" if true then do your thing else do nothing.

@rohangroombridge

cheers :smiley:

Happy learning :smiley:

1 Like

Hi, Thank you for replying. Is there a way to do it without a for loop?

1 Like

yes it has.
DataTable.Rows(0)(“columnname”).ToString = ""

@rohangroombridge

cheers :smiley:

Happy learning :smiley:

1 Like

Hi,

You can check it by the following single sentence.

hasValue = dt.AsEnumerable.Select(function(r) r("ColumnName").ToString="Value").Contains(true)

Regards,

@rohangroombridge

Yes we can do that. Use below LINQ query.

int nullCount = yourDT.AsEnumerable.Where(Function(row) row("columnname") is DBNull.Value or Convert.Tostring(row("columnname")).Trim = "").CopyToDataTable.Rows.Count

If it is greater than zero then it contains null values else it doesn’t contain.

1 Like