How to add data row in different data table of different column using linq

Hi Team,

Here i am having data table Dt_1 where i need to add this data row in different data table having different column names as shown below

DT_1:

DT_1

DT_Final(Expected output)

DT_Final

Please suggest any solution using LINQ

Regards,
Sai Adarsh.

@adarsh_kotagiri Datatable-> DT_1 & DT_Final and Create “Result” argument as “in/out” direction.

In Total 3 Datatable will be used,
DT_1 , DT_Final and Result

Take Involve Code Activity, Pass the DT_1 & DT_Final argument as “in” direction. then open the Code Editor,

Var query = from DT_1 in DT_1.AsEnumerable()
Join DT_Final in DT_Final.AsEnumerable() on DT_1.Field(“Document Number”)
equals DT_Final.Field(“Cheque.no”)
select new

        {
            Date = DT_1.Field<string>("Date")
            Cheque.no = DT_Final<double>("Cheque.no")
            Amount = DT_Final<double>("Amount")
        }

      foreach (var item in query)
    {
        result.Rows.Add(new Object[] {item.Date, item.Cheque.no, Item.Amount})
     }

I am 100% sure it will be work. I have tested it too !!

Happy Learning !!

3 Likes

Why do you want to use Linq? Add Data Row will work just fine.

1 Like

By the way, it looks like what you really need to do is just add the Supplier column and rename the Document Number column. Why bother moving data between datatables when you don’t need to?

Hi @adarsh_kotagiri,

What about below

Input
image

Output
image

Workflow

Xaml
Sequence.xaml (9.5 KB)

Query

(From row In dt1.AsEnumerable
Let outrous = (row("Date").ToString+","+row("Document Number").ToString+",,"+row("Amount").ToString).ToString
Select dt2.Clone.Rows.Add(outrous.Split(CChar(",")))).copytodatatable

Thanks,
Rajkumar

2 Likes

Thank you so much its working fine

Thank you for the brief explanation.

1 Like

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