Find the largest value from DT column where value in alphanumeric e.g. CEG40

Hi team

I extracted the data from an application in Data table. now, I am trying to find out a largest value the one of the column of data table. have tried following in assign activity.

dtConfig.AsEnumerable().Max(Function(row) (row(“Configuration”))).tostring

But getting an error. Error is saying that value must be string format where value is like CEG40. please help me on this.

Hi,

If you need 40 as result, the following works.

dtConfig.AsEnumerable().Max(Function(row) CInt(System.Text.RegularExpressions.Regex.Match(row("Configuration").ToString,"\d+").Value)).ToString

If you need CEG40 as result, the following will work.

dtConfig.AsEnumerable().OrderBy(Function(row) CInt(System.Text.RegularExpressions.Regex.Match(row("Configuration").ToString,"\d+").Value)).Last().Item("Configuration").ToString

Regards,

Thanks for your reply!!

Now, getting an exception as mention below.

RemoteException wrapping System.InvalidCastException: Conversion from string “” to type ‘Integer’ is not valid. —> RemoteException wrapping System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value,
NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
— End of inner exception stack trace —
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
at Namespace_8efb.DataIn_Expressions.DataIn_Expressions_TypedDataContext12_ForReadOnly._Closure$__._Lambda$__22-0(DataRow row)
at System.Linq.EnumerableSorter2.ComputeKeys(TElement[] elements, Int32 count) at System.Linq.EnumerableSorter1.Sort(TElement elements,
Int32 count)
at System.Linq.OrderedEnumerable1.GetEnumerator()+MoveNext() at System.Linq.Enumerable.TryGetLast[TSource](IEnumerable1 source,
Boolean& found)
at System.Linq.Enumerable.Last[TSource](IEnumerable1 source) at Namespace_8efb.DataIn_Expressions.DataIn_Expressions_TypedDataContext12_ForReadOnly.__Expr111Get() at Namespace_8efb.DataIn_Expressions.DataIn_Expressions_TypedDataContext12_ForReadOnly.ValueType___Expr111Get() at Namespace_8efb.DataIn_Expressions.InvokeExpression(Int32 expressionId, IList1 locations,
ActivityContext activityContext)
at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(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.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument, Int32 nextArgumentIndex, ActivityExecutor executor, IDictionary2 argumentValueOverrides,

Hi,

It’s because there is value not including numeric character (or blank).

Can you try the following, if you can ignore it.

dtConfig.AsEnumerable().Where(Function(row) System.Text.RegularExpressions.Regex.IsMatch(row("Configuration").ToString,"\d")).Max(Function(row) CInt(System.Text.RegularExpressions.Regex.Match(row("Configuration").ToString,"\d+").Value)).ToString


dtConfig.AsEnumerable().Where(Function(row) System.Text.RegularExpressions.Regex.IsMatch(row("Configuration").ToString,"\d")).OrderBy(Function(row) CInt(System.Text.RegularExpressions.Regex.Match(row("Configuration").ToString,"\d+").Value)).Last().Item("Configuration").ToString

Regards,

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