Link to home
Start Free TrialLog in
Avatar of countrymeister
countrymeister

asked on

How to orderby a linq query with a join to two tables and output the data to a predefined datatable

I need to order this linq query by ID and then by Date
I have two datatables dt1 and dt2

and then I have a predefined table called joinedTable with columns ID, Code, Date, Price

DataTable joinedTable = GetDataTable();
 var result = from dataRows1 in infocodesDT.AsEnumerable()
                         join dataRows2 in mqDT.AsEnumerable()
                         on dataRows1["InfoCode"] equals dataRows2["InfoCode"]

                         select joinedTable.NewRow().ItemArray = new object[]{
                             dataRows1["SecurityID"],
                             dataRows2["MarketDate"],
                             dataRows2["OpenPrice"],
                             dataRows2["ClosePrice"],                        
                             dataRows2["VWAP"],
                             dataRows2["TotalReturnIndex"],
                         };
SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Does this,   select joinedTable.NewRow().ItemArray = new object[]{,  actually work on your system?
Avatar of countrymeister
countrymeister

ASKER

Yes, that works, and so does the last linq query I posted with the order by.
I do not have to create that extra class. Give it a try and let me know.
I did not have to create a new class