How to use ternary without else?

Hi… I want add row to dtOutput with ternary condition, how to skip add row if the condition is false ?
i make this code, but error “The source contains a DataRow reference that is null”

dtOutput = dtInput.AsEnumerable.Select(Function(x) If(x(“WSID”).ToString.Substring(0,1)=“Z”,dtOutput.Rows.Add(New Object(){“Z1”,“Z2”,“Z3”}),Nothing)).CopyToDataTable

Hi @Iwan_Kurniawan2

Have a look on the thread

Regards
Gokul

1 Like

Hi @Iwan_Kurniawan2 ,

You can use For each Row in Input Datatable, Check the conditions and subsequently add the row which matches the conditions into the output table. Im not sure of using LINQ for this scenario but maybe you should stick to the Uipath Activities.

Hi @Iwan_Kurniawan2

Could you give a try to this LINQ

dtOutput =

(
	From row in dtInput
	Where row("WSID").ToString.Substring(0,1).Equals("Z")
	Select dtOutput.Rows.Add(New Object(){"Z1", "Z2" ,"Z3"})
).CopyToDataTable

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