Click here to Skip to main content
15,893,368 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
var prices= from st in obj.Wishlist_tables
join X in obj.movie_details on st.movie_id equals X.Id
where st.username == Session["user"].ToString()
select new { X.price }
now i have some prices of some products and i want to add them and want to show in a label
Posted
Comments
Harshil_Raval 17-Sep-13 2:41am    
Just cast it to integer and add other prices to it, and display in label. What problem you face here?
Omprakash Kukana 17-Sep-13 2:45am    
int x = prices.Count();

foreach(var objdata1 in prices)
{
int[] ary = new int[x];
for (int i = 0; i < x ; i++ )
{
ary[i] = convert.toint32(objdata);
}
Omprakash Kukana 17-Sep-13 2:48am    
and this erroe is ngenerting
Unable to cast object of type '<>f__AnonymousType2`1[System.Nullable`1[System.Int32]]' to type 'System.IConvertible'.
Harshil_Raval 17-Sep-13 2:51am    
So, here numb is list of integer. Right? You want to count these numbers?
Omprakash Kukana 17-Sep-13 2:53am    
i update there is not numb where is prices which is having the values from linq query and now i want to add these prices to find out total price

OK,
try to change your linq query to this,
C#
var prices= from st in obj.Wishlist_tables 
            join X in obj.movie_details on st.movie_id equals X.Id 
            where st.username == Session["user"].ToString() 
            select X.price; 

And then count it.. 

int count=0; 
foreach(var objdata1 in prices) 
{ 
    count+=Convert.ToInt32(objdata1); 
}

or

count = prices.Sum();

Hope it helps you..
 
Share this answer
 
v2
Comments
Omprakash Kukana 17-Sep-13 3:54am    
yues its working 10nx mr. Harshil_raval
JOE Heart Under Blade 17-Sep-13 4:16am    
the reason why my vote of 5 is...
this is what i m looking for....tq.
basically var is new keyword which compiler set at run time. so it depened wht you are expecting that var to be. If you are expecting var as list you can use the normal syntax used for list and can add value to that.
-SG
 
Share this answer
 
Comments
Omprakash Kukana 17-Sep-13 3:09am    
how can i add values of var type variable i put brakpoint and checked then i found that here is two values in a var type variable prices now i want to add them
do this

int totalPrices = prices.Sum();
 
Share this answer
 
Comments
Omprakash Kukana 17-Sep-13 3:14am    
not working error:
AnonymousType#1[]' does not contain a definition for 'Sum' and the best extension method overload 'System.Linq.Queryable.Sum(System.Linq.IQueryable<int>)' has some invalid arguments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900