troubleshooting Question


Avatar of countrymeister
countrymeister asked on
.NET ProgrammingC#SQL
1 Comment1 Solution955 ViewsLast Modified:
I have a List<int> dateList

and a DataTable dt with three columns
(Code string,
BusDate int,
Price double
ABC  20130531  5
ABC  20130602  4
ABC  20130603  7
LMN  20130601  3
LMN  20130602  2

I need to get for all the given dates in the List, the corresponding codes and prices.
If the date does not exist in the datatable, get the previous days price. Order by Code and date

The final result set should look like this based on the above example

ABC  20130531  5
ABC  20130601  5
ABC  20130603  7
LMN  20130531  NULL
LMN  20130601  3
LMN  20130603  2

This does not work
 var query = from c in dateList.AsEnumerable()
                        join p in dt.AsEnumerable() on c equals p["BusDate"] into ps
                        from p in ps.DefaultIfEmpty()
                        select new { BusDate = c, Code = p["Code"],  Price = p["Price"] };
Ioannis Paraskevopoulos

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros