How to get maximum length of a string for a particular column in a datatable
Hi @Prem_Chand1 ,
Using this you can get it
or if you need maxlength of your column:
You can use the following query in the Assign activity to get the desired result:
maxLength = dataTable.AsEnumerable().Max(Function(row) row.Field(Of String)("ColumnName").Length)
Here, maxLenght is a variable of type Int32.
Hope this helps,
When: the longest string in the column
Then: as mentioned above with the usage of LINQ Max Operator
When: the data column config setting is meant
Thanks so much I tried many ways but it could saved my day
Can you suggest best way to learn linq @arjunshenoy
I tried this way it will give -1
It might be the case that the maxlength is not set for that column, that means it could take a string of any length.
You would have read the DataTable from some source, hence this -1 is coming.
have a look here
The following resources might help you with the learning:
Len function in an
If condition to compare the length of the current value with the
maxLength variable. If the length is greater, update
maxLength with the new value.
Assign activity: maxLength = 0
For Each Row activity (DataTable = yourDataTable)
Assign activity: currentValue = row(“ColumnName”).ToString()
Assign activity: currentLength = Len(currentValue)
If activity: currentLength > maxLength
Assign activity: maxLength = currentLength