[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-03-24
6
Medium Priority
?
461 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 75

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 75

Accepted Solution

by:
käµfm³d   👽 earned 500 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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 75

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

868 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