Clear Datatable

I wanted to clear datatable if it contains header. Was suggested to use DataTable.Columns.count > 0 to check. But I encounter an issue if the datatable hasn’t been populated yet as null is not an instance of an object. Please advise.

Hi @QTH ,
Have you tried activity
image
regards,
LNV

you can do a null check

IF(Not isNothing(YourDatatableVar),YourDatatableVar.Clone, new DataTable() )

1 Like

HI

How about the following?

dt = New DataTable()

image

Regards,

HI @QTH

You can try this
if condition = dt.columncount>0

@QTH

image

Thanks all for the replies but as shared in my initial post there may be instances where the datatable isn’t populated yet and hence the solutions asking to count the columns will return an error. The suggestion to do a null check seems to work for non populated datatable.
Same goes for the approach to just reassign it as a new datatable but I’ve yet to check.

Thanks all for the advice.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.