Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Public Sub increment()



        If cnn.State = ConnectionState.Closed Then
            cnn.Open()

        End If

        Dim bookid As Double
        bookid = ds.Tables(0).Compute("Max(Book_id)", Nothing)

        TextBox14.Text = bookid + 1


 End Sub



'This code works but not instantly. When I click the button where the sub function inrement() is being called works fine, but when I click the button to add next record, the textbox gets the same value. So, eventually, adding first record works fine but when I click the button to increment the value by 1 as I want to add next record it gets the same value. I'm having to close and reopen the form every time I want the value to be incremented. So I'm wondering if somebody could help me to solve this problem. Thanks.
Posted

It happens because Your dataset returns cached value.

Try this...


VB
If cnn.state<>1
   cnn.open()
End If

cmd.commandText="select max(id) from table"
Textbox1.text=cmd.ExecuteScalar()
 
Share this answer
 
In the database i.e. dataset, you are not updating the booking id here. So everytime you say max(book_id), it will keep giving you same number.
Either this is the problem, or you have not showed us the remainder of the code.

Milind
 
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