Click here to Skip to main content
12,358,418 members (48,364 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
Public Sub increment()

        If cnn.State = ConnectionState.Closed Then
        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 13-Jan-13 23:23pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

It happens because Your dataset returns cached value.

Try this...

If cnn.state<>1
End If
cmd.commandText="select max(id) from table"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100