Null Error in IF Condition

19.2.0+Branch.master.Sha.21b678a4c3a8b1362fcdd6e92496f991e5a7da37

Source: If

Message: Object cannot be cast from DBNull to other types.

Exception Type: System.InvalidCastException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidCastException: Object cannot be cast from DBNull to other types.
at System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider)
at System.Convert.ToInt32(Object value)
at lambda_method(Closure , ActivityContext )
at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context) at System.Activities.CodeActivity1.InternalExecuteInResolutionContext(CodeActivityContext context)
at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance, Activity1 expressionActivity) at System.Activities.InArgument1.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance activityInstance, ActivityExecutor executor)
at System.Activities.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance targetActivityInstance, ActivityExecutor executor, Object argumentValueOverride, Location resultLocation, Boolean skipFastPath)
at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument, Int32 nextArgumentIndex, ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate) at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Make sure the variables used in the IF condition are initialized to some values.

Regards,
Karthik Byggari

1 Like

Hi,
Before you check for the condition use a write line to check if there is any value present.

Regards,
Pavan H

@pavanh003
I m using Excel scope to read a column and for each row to get each value.
Convert.ToInt32() this code is used for converting column values so that i can subtract few different column values and check it with another datatable Value.
So as You suggested i checked and when a assigned value is null then it show the error.
can you tell me how to check row value is null if its null i need to break the process.

Thankyou @pavanh003 for you answer. I hope You can help Me with this Flow :grinning:

@Shivaramthorn

Please check the variable having null values.

If it is not please share more details on this.

Thanks,
Pradeep Sridharan

1 Like

I assigned it to a variable.
Thankyou for the Answer @KarthikByggari

Is this the Right way to check null values.

Regards
Shivaram

@Shivaramthorn:

Nope, Tostring does not allow null values and it is throwing error.

Use convert.tostring and check this condition

String.IsNullOrEmpty(Convert.ToString(strTest))

Thanks,
Pradeep Sridharan

1 Like

Hi,
inside for loop use a if condition and check this condition:
isNothing(row) for the row, if it is nothing break the loop using break activity

let us know if this helps

Regards,
Pavan H

Hi,

Please refer the image and let us know

image

Regards,
Pavan H

Thanks @Pradeep
For My Problem This is the Right answer the bot executed successfully.

Regards
Shivaram

1 Like

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