Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 13-Jan-13 23:23pm
Rate this: bad
good
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.
 
Milind
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

It happens because Your dataset returns cached value.
 
Try this...
 

If cnn.state<>1
   cnn.open()
End If
 
cmd.commandText="select max(id) from table"
Textbox1.text=cmd.ExecuteScalar()
  Permalink  

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 548
1 CHill60 390
2 OriginalGriff 323
3 BillWoodruff 213
4 PIEBALDconsult 185


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