Link to home
Start Free TrialLog in
Avatar of doramail05
doramail05Flag for Malaysia

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,
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

Open in new window

Avatar of LDH
LDH
Flag of Netherlands image

Try the code below.

lastid = Right("JPE0000003", 4)
lastid = CInt("1" & lastid)
lastid = lastid + 1;
lastid = "JPE" & Right(Cstr(lastid), 1)

Open in new window

Modify the query to return the maximum record (that having 'JPE00000003')

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

Open in new window

Assuming the first part 'JPE' is having 3 characters.

Raj
Avatar of doramail05

ASKER

ya, any codes for sorting out the maximum record = JPE00000003
strSQL = "SELECT * FROM cardholder ORDER BY [idfield] DESC"

ASKER CERTIFIED SOLUTION
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial