Solved

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

Posted on 2011-03-24
6
430 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 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 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