Linq query to add one more column

Hi All,

Can you pls advise how can i modify this linq query to add one more column.

(From table1 In Dt1.AsEnumerable() Join table2 In dt2.AsEnumerable() On table1.Item(“Merchant Charge Ref”).ToString Equals table2.item(“Cheque No.”)
Let ra = table1.ItemArray.Concat(New Object(){table2(“Cheque No.”),table2}).toArray
Select r = FilterData1.Rows.Add(ra)).copytodatatable

Thanks
Taruna

Hi @taruna.mehra ,

Could you provide us with what are the column Names in the Input Datatables and what is the Output format required ?

We see that you are using table2 in the array which I guess maybe causing the issue.

Do you get an Irregular output ?

From table 2 i need 2 columns, (BT Advise number) and Payment id.

This would all be much simpler if you’d just use the Join Data Table activity.

Its not working thats why i am using it.

Hi @taruna.mehra

Try this

(From table1 In Dt1.AsEnumerable()
Join table2 In dt2.AsEnumerable() On table1.Item(“Merchant Charge Ref”).ToString() Equals table2.item(“Cheque No.”)
Let ra = table1.ItemArray.Concat(New Object() {table2(“Cheque No.”), table2, “Additional Column Value”}).ToArray()
Select r = FilterData1.Rows.Add(ra)).CopyToDataTable()

Thanks!!

1 Like

Hi Nitya,

do i need to add the other colum name here"“Additional Column Value"

Thanks
Taruna

Hi @taruna.mehra

Yes right.

Thanks!!

1 Like

@taruna.mehra ,

Check the below Linq Expression :

(From table1 In Dt1.AsEnumerable() Join table2 In dt2.AsEnumerable() On table1.Item("Merchant Charge Ref").ToString Equals table2.item("Cheque No.")
Let ra = table1.ItemArray.Concat(New Object(){table2("BT Advise number"),table2("Payment id")}).toArray
Select r = FilterData1.Rows.Add(ra)).copytodatatable

The above Query should work provided that FilterData1 has number of columns in table1+2

Also, Not so sure Why initially you were adding Check No. column in the Output.

Also, Would like to know what exactly was the issue in using the Join Datatables activity.

am testing the bot just wait

1 Like

Hi am getting this below errors.

Assign: Input array is longer than the number of columns in this table.

Thanks
Taruna

Join data table is not working. the code had join data table and one column had special character. i replaced it also but it was not showing any data.

Thanks
taruna

Hi @taruna.mehra

Check this updated one-

Dim filteredData = (From table1 In Dt1.AsEnumerable()
Join table2 In dt2.AsEnumerable() On table1.Item(“Merchant Charge Ref”).ToString() Equals table2.Item(“Cheque No.”)
Let ra = table1.ItemArray.Concat(New Object() {table2(“Cheque No.”), table2, “Additional Column Value”}).Take(FilterData1.Columns.Count).ToArray()
Select r = FilterData1.Rows.Add(ra)).CopyToDataTable()

Thanks!!

Hi am getting this below errors.

Assign: Input array is longer than the number of columns in this table.

Thanks
Taruna

Hi am getting this below errors.

Assign: Input array is longer than the number of columns in this table.

Thanks
Taruna

Join Data Table works fine. I use it all the time.

Show me how you’ve got it set.

hI Postwick,

its office work, can not show you but its with inner join.

Both dt and one dt has been assigned as output.

Thanks
Taruna