Solved

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

Posted on 2011-03-24
6
443 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS2010 Build fails to install 14 82
SQL Server maintenance plan 8 54
query output (script) from a stored procedure 4 39
How to escape alias names for Oracle query 1 25
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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