Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello all,

i try to do sum of row of my database.

i have this error :
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'float)


this is my query :
ASP
<pre>                System.Nullable<float> totalUnitsOnOrder =
    (from prod in dbcontext.Votes
     where prod.BvId == bureauvote
     select (float)prod.NbrVoix)
    .Sum();


i use mysql from cpanel, and mysql server version is 5.6

What I have tried:

i have try other way to do that , but same error

way 1 :
ASP
<pre>                var res = dbcontext.Votes.Where(v => v.BvId == bureauvote);
                var result = res.AsQueryable().Sum(r => r.NbrVoix);



and this :
HTML
var res = dbcontext.Votes.Where(v => v.BvId == bureauvote).Sum(v => v.NbrVoix);


but always the same error. can you help me please.

thanks you all
Posted
Updated 24-Oct-20 11:32am
Comments
Richard MacCutchan 24-Oct-20 13:28pm    
Try removing the (float).
Member 13220552 24-Oct-20 13:54pm    
i have done, it's same

SQL
where prod.BvId == bureauvote

You only need a single equals sign in SQL:
SQL
where prod.BvId = bureauvote
 
Share this answer
 
Comments
Member 13220552 24-Oct-20 14:20pm    
Richard i have try with one equals, i have error on my code , when i try with equals function it's the same exception
Member 13220552 24-Oct-20 17:31pm    
i have found solution , i have done select on table , after i have done foreach on the queryable data
i have found solution , i have done select on table , after i have done foreach on the queryable data
 
Share this answer
 

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