DataRow value assignment based on condition

Hi All,

I’m building a datatable from an existing datatable considering only few integer columns. Have to assign the value to the datarow only if the amount is positive.

Steps followed:
Created datatable using Build datatable activity.
Created column Total Amount as Integer with Allow Null checked.
Used for each row on existing datatable.
Used assign activity with if condition got error cannot infer common type:

if(CInt(row(“TotalAmount”).ToString) >0,Cint(row(“TotalAmount”).ToString),System.DBNull.Value)

Have attached the xaml file for reference.
DataRow_IfCondition.xaml (11.0 KB)
DataInput.zip (5.5 KB)

Any kind of assistance would be of great help

Cite: “CInt(row(“TotalAmount”).ToString) >0”
If Total Amount will be nothing, than you can’t compare “” string with 0. It will throw an error.

2 Likes

Hi olgu,

Thanks for the input. :slight_smile: Got it This expression work well:
If(Convert.ToInt32(row(“TotalAmount”)) >0,row(“TotalAmount”),System.DBNull.Value)

You sure? I’ve checked this statement If(Convert.ToInt32(row(“TotalAmount”)) >0 for “” string and it is still throwing error.

Hi olgu,

Yup it indeed worked. Have attached xaml for reference and the output file. My end result is as expected.DataRow_IfCondition.xaml (11.6 KB)
DataInput.zip (6.0 KB)

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