Click here to Skip to main content
11,710,943 members (82,938 online)
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 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
0 Sergey Alexandrovich Kryukov 549
1 OriginalGriff 255
2 Peter Leow 154
3 Maciej Los 120
4 Abhinav S 120
0 Maciej Los 95
1 Richard MacCutchan 90
2 Abhinav S 90
3 OriginalGriff 80
4 Member 4653839 50

Advertise | Privacy | Mobile
Web03 | 2.8.150819.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