Unable to cast object of type ‘System.Double’ to type ‘System.String’ Error

Hello, all

I’m facing below error message on this assign activity.
Is there any one who knows how to solve it?

[Error 1]
Dt_keyword2.AsEnumerable().Select(Function(a) a.Field(Of String)(“Outplus”).ToString).ToArray

[Error 2]
Dt_keyword2.Select(“Outplus <> ‘Null’ or Outplus <> ‘0’”).CopyToDataTable

Datatable “Outplus” column only contains Null and 0 and Int value


Thank you

Hello @I would like to help you, can you share the File to test and give you a solution, becuase you are implemeting well the code

1 Like

Masterfile_HSBC001_test.xlsx (18.1 KB)
Hello, I’m unable to upload .xlsm file but it meant to be xlsm extension.
Thank you for helps !
BlankProcess_test.zip (12.0 KB)

It’s funny because like I said, your code was good, in fact it is working fine

To the left you can see the result, maybe try to replace the assign, let me know what happen

1 Like

Thank you for prompt checking !
First Assign has been succeeded after I replaced to Multi assign but still facing similar error 2nd assign activity.
Could you please try this one as well?
data should be stored to Array and I’m going to compare with other excel file’s column value.
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidOperationException: Can not assign ‘Dt_keyword2.AsEnumerable().Select(Function(a) a.Field(Of String)(“Outplus”).ToString).ToArray’ to ‘St_Arr_keyword2’. ----> System.InvalidCastException: Unable to cast object of type ‘System.Double’ to type ‘System.String’.
at System.Data.DataRowExtensions.UnboxT1.ReferenceField(Object value) at System.Data.DataRowExtensions.Field[T](DataRow row, String columnName) at lambda_method(Closure , DataRow ) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at System.Linq.Buffer1..ctor(IEnumerable1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) 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, IDictionary`2 argumentValueOverrides, Location resultLocation, Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
— End of inner ExceptionDetail stack trace —
at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Yeah it works you only need to change the type in the Query, you are using “OF String” and you need “Of Double”

Try it and let me know what happen

1 Like

Oh… it works!!! Thank you so much. If it is not border you. could you please share what is difference btw Of Sting and Of Double in this case ?

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