Error in Concating Columns

Hi Team,

I need to Concat 3 columns and insert in a new column.
I have write a code for that, attaching below but the issue is the one of the 3 columns are having few blank rows and it is throwing an error.
What can be a solution for this?

Thanks,
Yash

Hi @yash.choursia

Check with this

downloadedfile_DT.AsEnumerable().ToList().ForEach(Sub(row)
    row(40) = $"{Convert.ToString(row(39))}{Convert.ToString(row(10))}{Convert.ToString(row(11))}"
End Sub)

Hello @yash.choursia

For Each row In YourDataTable.Rows
column1Value As String = row(“Column1”).ToString
column2Value As String = row(“Column2”).ToString
column3Value As String = row(“Column3”).ToString

 Check if any of the columns have a blank value
If Not String.IsNullOrWhiteSpace(column1Value) OrElse Not String.IsNullOrWhiteSpace(column2Value) OrElse Not String.IsNullOrWhiteSpace(column3Value) Then
     Concatenate non-blank values and insert them into the new column
    row("NewColumn") = $"{column1Value} {column2Value} {column3Value}".Trim()
End

Thanks & Cheers!!!

Hi, try to use below expression

downloadedfile_DT.AsEnumerable().ToList().ForEach(Sub(row) row(40) = String.Concat(row(39).ToString, row(10).ToString, If(row.IsNull(11), “”, row(11).ToString)))

not working @pravallikapaluri

not working @neha.upase

Hi @yash.choursia

Try this query:

Assign activity:

dt = (From row In dt.AsEnumerable()
      Let value39 = If(Not IsDBNull(row(39)), row(39).ToString(), String.Empty)
      Let value10 = If(Not IsDBNull(row(10)), row(10).ToString(), String.Empty)
      Let value11 = If(Not IsDBNull(row(11)), row(11).ToString(), String.Empty)
      Select row.Field(Of String)(40) = String.Concat(value39, value10, value11)).CopyToDataTable()

Hope it helps!!

showing error @Parvathy

@yash.choursia

Try the below following code in Invoke Code activity:

For Each row As DataRow In dt.Rows
    Dim value39 As String = If(Not IsDBNull(row("Column39")), row("Column39").ToString(), String.Empty)
    Dim value10 As String = If(Not IsDBNull(row("Column10")), row("Column10").ToString(), String.Empty)
    Dim value11 As String = If(Not IsDBNull(row("Column11")), row("Column11").ToString(), String.Empty)
    
    row("Column40") = String.Concat(value39, value10, value11)
Next

Hope it helps!!

1 Like

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