doramail05
asked on
vb.net get maximum id after JPE000003
i have 3 records in cardholder table where would like to take the last id
JPE00000001
JPE00000002
JPE00000003
and make a string call JPE0000004
with the code below,
JPE00000001
JPE00000002
JPE00000003
and make a string call JPE0000004
with the code below,
Try
Using objDataCtrl As New DBCore(gstrConnectionStr)
strSQL = "SELECT * FROM cardholder"
objReader = objDataCtrl.ExecuteReader(strSQL, "")
If objReader.Read Then
End If
End Using
Catch ex As Exception
strError = ex.Message
End Try
Modify the query to return the maximum record (that having 'JPE00000003')
Then write code like attached.
Raj
Then write code like attached.
Raj
Dim sLastString As String
Dim nLastValue As Integer
sLastString = "JPE00000003" '' <-- From query
sLastString = Convert.ToInt32(Right(sLastString, Len(sLastString) - 3))
sLastString = Left(sLastString, Len(sLastString) - Len(Convert.ToString(nLastValue + 1))) & nLastValue + 1
Assuming the first part 'JPE' is having 3 characters.
Raj
Raj
ASKER
ya, any codes for sorting out the maximum record = JPE00000003
strSQL = "SELECT * FROM cardholder ORDER BY [idfield] DESC"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window