0

I have tried this , but i don't know how to manipulate LINQ query to find difference between two columns from the data table.

I have two datatables dtStockTransactionData and dtStocksData. Below code explains how I have manupulated the result

DataTable dtMerged = (from a in dtStockTransactionData.AsEnumerable()
                      join b in dtStocksData.AsEnumerable()
                      on a["exchangesymbol"].ToString() equals b["exchange_symbol"].ToString()
                      into g
                      where g.Count() > 0
                      select a).CopyToDataTable();
grdErrSTSData.DataSource = dtMerged;
grdErrSTSData.DataBind();
return dtMerged;
J.SMTBCJ15
  • 471
  • 6
  • 20

1 Answers1

0

If I understood your question you can do this using link query with select new keyword.This is a example for Link with join -

from a in db.table1
   join b in db.table2 on a.valueA equals b.valueB
   select new { A = a.valueA, B = valueB};

As your code:

 var selected = from a in dtStockTransactionData.AsEnumerable()
                      join b in dtStocksData.AsEnumerable()
                      on a["exchangesymbol"].ToString() equals b["exchange_symbol"].ToString()
                      into g
                      where g.Count() > 0
                      select new{ 
                         value1 = a.wantedValue,
                         value2 = b.wantedValue
                      }

Then you can get result using selected

After that you can compare data in own way.

Refer this Return list using select new in LINQ

Community
  • 1
  • 1
Thili77
  • 1,061
  • 12
  • 20
  • can you please provide me the syntax of calculating the difference between two columns and adding the result in a new column.... – user1879916 Mar 09 '17 at 09:54