Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: 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 14-Jan-13 0:23am
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
0 Sergey Alexandrovich Kryukov 8,373
1 OriginalGriff 6,466
2 Peter Leow 3,567
3 Zoltán Zörgő 3,316
4 Richard MacCutchan 2,397

Advertise | Privacy | Mobile
Web01 | 2.8.150123.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2015
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