BOOKID Increment problem

sql server India
  • 13 years ago

    I am develioping library system using Visual Basic6 and SQL sever 2000. IN this system while adding new BOOk entry i want BOOKID should be like "BXXXX" (e.g. for first record it should be "B0001". I have designed the table for book where my BookID field is of Integer type.

    I have created following function (LOADBOOKID) to increment the BOOKID.But my problem is it is not incrementing what is the problem, it is giving type conversion error and it is not incrementing what is wrong in the code

     

    New Book Entry

    1.   Private Sub LOADBOOKID()

    2.   Dim SR as Integer

    3.   DIM SRPLUS as String

    4.   Dim RSC As New RecordSet

    5.  RSC.Open “SELECT * FROM BOOKDETAILS”, Connect, adOpenStatic,          adLockOptimistic, adCmdText

    6.  SR=RSC!BookID

    7. SRPLUS=SR+18. Txtbookid.Text= “B”&Format(SRPLUS,”0000”)

    9. RSC.Close

    End Sub

      Private Sub Form_Load()LOADBOOKIDEnd sub Private Sub Command1_click()LOADBOOKIDDim RSCAs New Recordset RSCAs.open “SELECT * FROM BOOKDETAILS”, Connect, adOpenStatic, adLockOptimistic, adCmdText

    .............

    .........

    .......

    .......

    end sub

    Please help what is the problem..

  • 13 years ago

    You might want to look at the following:

    2.   Dim SR as Integer

    3.   DIM SRPLUS as String

    6.  SR=RSC!BookID

    7. SRPLUS=SR+18. Txtbookid.Text= “B”&Format(SRPLUS,”0000”)

    SRPlus is setup as string. SR is integer. Perhaps SRPLUS should be integer? ... or simply: Txtbookid.Text = "B" & Format(SR + 18, "0000") .. unless of course you use SRPLUS elsewhere in the program.

    Joe 

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.”