Solved

Largest value of a field (type int) in C#

Posted on 2011-03-24
6
409 Views
Last Modified: 2012-05-11
I have a field (RcdId) which is of Int type.  I would like to extract the value of the largest one in the table.  In this example I want the result of 236.  I posted code using Max and Asc but they do not work in C#.  Your help is appreciated.
Emp No         RcdId
101      235
102      236
103      222
104      24
105      91

My environment is Visual Studio, the language is C# and I'm attached to a SQL Server db.

var LastRcdId = (from c in dbTimeClockPlus.EmployeeLists where Max(c.RecordId)ASC select c.RecordId).FirstOrDefault();

Open in new window

0
Comment
Question by:BobRosas
  • 3
  • 2
6 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35211179
Try this:

var LastRcdId = (from c in dbTimeClockPlus.EmployeeList select c.RecordId).Max(c.RecordId);

Open in new window

0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 125 total points
ID: 35211192
Correction:

var LastRcdId = (from c in dbTimeClockPlus.EmployeeList select c.RecordId).Max();

Open in new window

0
 
LVL 22

Expert Comment

by:p_davis
ID: 35211345
pretty much a repeat of kaufmed's solution.
//using System.Linq;
int LastRcdId = dbTimClockPlus.EmployeList.Max(rec => rec.RecordId);
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

Author Closing Comment

by:BobRosas
ID: 35211603
Thank you both for your quick response.  Kaufmed was 1st and it worked like a charm!  So I awarded him points but I think all you EE guys are great!  Thanks again!
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35212228
NP. Glad to help.   = )
0
 
LVL 22

Expert Comment

by:p_davis
ID: 35216088
ya, didn't expect points just offering another way to do the same thing.
glad you got your answer.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now