Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operator '==' cannot be applied to operands of type 'int' and 'System.Linq.iQueryable<int>'

Tags:

c#

sql

linq

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;
}  
like image 219
T.J. Wallace Avatar asked Apr 19 '13 14:04

T.J. Wallace


1 Answers

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)

like image 99
Geoff Avatar answered Oct 03 '22 15:10

Geoff