So I'm a bit stuck! Doing a programming assignment for college and I hit a wall.
The question we were given in one of our parts is as follows:
"2. Allow the user to find the customers that have placed an order in a particular year. Provide a combo box which lists all the unique (distinct) years in orders table from which the user can make a selection."
I'm having an issue with converting the "Year" so I can compare it with the OrderID and display all the orders that are in the database, in a listbox.
If anyone could give me a hand it would be greatly appreciated! Thanks!
Here's my code:
private void dateDDL_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string selection;
selection = dateDDL.SelectedItem.ToString();
var year = from y in northwind.Orders
where Convert.ToString(y.OrderDate).Contains(selection)
select y.OrderID;
var order = from o in northwind.Order_Details
where o.OrderID == year
select new { o.OrderID,
o.ProductID,
o.UnitPrice,
o.Quantity,
o.Discount };
lbxOrderdate.ItemsSource = order;
}
Your year
query is returning a list of all the OrderID
values that match your where
clause. You can't compare that list to the single o.OrderID
in the order
query; if you want to find all the orders that are in one of the years returned by the years
query, use something like
where year.Contains(o.OrderID)
(untested, but should lead you down the right route)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With