If condition : either datatable is null

Hello all,

I have a question on how to give if in which if Either datatables ( DT1 , DT2) is null it should go into the THEN workflow

i.e if DT1 is null or DT2 is null or both DT1 and DT2 are null it should go onto the THEN block of the IF condition.

Kindly please help.

Hi @Yugal_Raju

If DT1 Is Nothing OrElse DT2 Is Nothing Then
    ' Your THEN block workflow here
    LogMessage("Either DT1 or DT2 is null.")
Else
    ' Your ELSE block workflow here
    LogMessage("Both DT1 and DT2 are not null.")
End If

Cheers!!

Hi @Yugal_Raju

Try this:

If
   IsNothing(DT1) OrElse IsNothing(DT2) OrElse IsNothing(DT1) AndAlso IsNothing(DT2)  
Then
    ' THEN workflow
    ' This block will execute if either DT1 or DT2 is null, or both DT1 and DT2 are null, or dt is null or contains only null or empty values
Else
    ' ELSE workflow
    ' This block will execute if none of the above conditions are met
End If

Hope it helps!!

Will this work of the DT has headers but no data ?

@Yugal_Raju

In that case try below

If (DT1 Is Nothing OrElse DT1.Rows.Count = 0) AndAlso (DT2 Is Nothing OrElse DT2.Rows.Count = 0) Then
    ' Your THEN block workflow here
    LogMessage("Either DT1 or DT2 has headers but no data.")
Else
    ' Your ELSE block workflow here
    LogMessage("Both DT1 and DT2 have data or do not have headers.")
End If

Actually the DT are not null they always contain headers (Sorry for the confusion from me)

So will it be

DT1.Rows.Count = 0 orElse DT2.Rows.Count = 0
Then:
Log (“Datatables have no data”)
Else
Log(“Atleast one of the Datatables have data”)

@Yugal_Raju

Yes, your understanding is correct. If the DataTables always contain headers and you want to check if they have no data, you can use DT1.Rows.Count = 0 OrElse DT2.Rows.Count = 0 in your condition.

If DT1.Rows.Count = 0 OrElse DT2.Rows.Count = 0 Then
    ' Your THEN block workflow here
    LogMessage("Datatables have no data.")
Else
    ' Your ELSE block workflow here
    LogMessage("At least one of the Datatables has data.")
End If

This condition checks if either DT1 or DT2 has no rows (no data) and will execute the THEN block if at least one of them has no data. If both DataTables have data or at least one of them has data, it will execute the ELSE block.

Hi,

If
IsNothing(DT1) OrElse IsNothing(DT2) OrElse IsNothing(DT1) AndAlso IsNothing(DT2)

Then
Condition True then this block will execute
Else
Condition False then this block will execute

If this works for you, please mark this post as a solution for others reference… :slight_smile:

Thanks

Hello,

Thank you it worked!

1 Like

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