Click here to Skip to main content
15,904,986 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
good day all, I need your help

I want to select the maximum and minimum value from the database ...

i have this this information in the database
name      amount  

john      20000
sarah     3000
kehinde   4444
johnson   200000

my code behind is
C#
// using linq to entity framework
  var rept = (from c in nameentity.name
              where c.name == "John"
              select c).ToList();

this get all all the values of john and sends them to the gridview but i want to show the maximum and mini value in the database like this
name      amount   minimum    maximum 
                   value      value 

john      20000    3000       200000

i have so many of the information on the database .. thanks for your time. i do appreciate
Posted
Updated 23-Aug-18 8:24am
v3

Try something like this :
C#
var rept_max = (from c in nameentity.name
                where c.name == "John"
                select c).Max(c => c.amount);

var rept_min = (from c in nameentity.name
                where c.name == "John"
                select c).Min(c => c.amount);
 
Share this answer
 
Same as above.....

rept_max = (from c in nameentity.name
where c.name == "John"
select c.amount).Max();

var rept_min = (from c in nameentity.name
where c.name == "John"
select c.amount).Min();
 
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