Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i use this code to get max value
C#
(From Tbl In db.tblRSInterests Select Tbl.intTrxId).Max()


BUT if table not have row (new Table) give me BUG
Posted
Updated 20-Oct-13 0:31am
v2
Comments
abbaspirmoradi 20-Oct-13 6:32am    
check if Table!=null and Table.Rows.count!=0 then do it..

can use this

VB
Dim intID As Integer
Dim isHAVE As Integer
isHAVE = (From Tbl In db.tblRSInterests Select Tbl.intTrxId).Count()

If (isHAVE = 0) Then
    intID = 1
Else
    intID = (From Tbl In db.tblRSInterests Select Tbl.intTrxId).Max() + 1  ' Samer Al-Dwaik
End If


if any one have thing better till me
 
Share this answer
 
Comments
Ranjan.D 20-Oct-13 12:24pm    
Note: The OP is asking for Linq solution.
Try this

Quote:
var maxLevelId = db.Characters.Where(o => o.UserID == UserID)
.Max(o => o.LevelID);
 
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