hi every one . when my form gets load it automatically fills th data using these two line

Me.CustomerTableAdapter.Fill(Me.NewBookingDataSet1.Customer)             "Customer info is displayed in text boxes on same form"

Me.BookingTableAdapter.Fill(Me.NewBookingDataSet1.Booking)               "Booking is displayed in data gridview"

when i use the the above two lines as comment then i get the empty form which i want. But problem is i have to click on plus(+) sign on binding navigator to get the fields and datagridview ready to enter the new record. when i click on (+) it gives me the next incremented id, i want to generate the id bu using click of a button. i dont want to use the plus sign. I want to have a button Add new booking. when i click there i get all fields and booking gridview ready to enter new records.

Dani AI

Generated

Short answer: the binding navigator’s + button simply asks the bound BindingSource to create a new row. Replicate that behaviour from a regular button and let the database own the identity value on save rather than trying to invent the next ID on the client.

Suggested approach (keeps bindings intact, shows an empty record only when needed):

  • Do not try to guess the next ID on the client with MAX(ID)+1; that approach (as suggested by ) is race-prone. If the database uses an IDENTITY or a sequence, let the DB assign the ID when the row is inserted and then refresh the row to get the server-assigned value.
  • To present a blank record on demand, call the BindingSource AddNew method from the Add button. This is the same action the navigator + performs.

Example code (place in the Add button Click handler):

Private Sub btnAddNewBooking_Click(sender As Object, e As EventArgs) Handles btnAddNewBooking.Click
    BookingBindingSource.AddNew()
    ' optional: set focus to the first input for faster data entry
    txtCustomerName.Focus()
End Sub

Saving the new row (EndEdit + Update) and then refreshing to retrieve the DB-assigned identity:

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
    Me.Validate()
    BookingBindingSource.EndEdit()
    BookingTableAdapter.Update(BookingDataTable)   ' update the DB
    ' refresh or re-read the saved row if the identity value is needed in the UI
End Sub

Notes and troubleshooting:

  • If bindings are created against an empty DataTable and controls disable, call the underlying adapter’s FillSchema or create an empty row programmatically so controls stay enabled until AddNew is clicked.
  • If showing the next ID before insert is an absolute requirement, use a server-side mechanism (sequence or stored proc that reserves/returns the next value) rather than client-side MAX(ID)+1.
  • ’s UI idea of relabelling the navigator control is simple, but adding a dedicated Add New Booking button gives clearer UX and full control over initialization (focus, default values, related lookups, etc.).

Recommended Answers

All 3 Replies

i cant get your point , but for getting id , you can get the max id by using datareader and then +1 and show it to your textbox.it is very simple.now can you please little bit explain your point. do you want to create whole form consisting of textboxes , grid dynamically ? or something else?

And regarding the use of the [+] button.
Can't you change the label to say "Add new booking" instead of a [+] sign?

i am talking about the plus sign on binding navigator to insert a new record.which automatically generates the next id from database and shows in the textbox. i want the same functionalioty but using a code under button. because of these two lines

Me.CustomerTableAdapter.Fill(Me.NewBookingDataSet1.Customer) "Customer info is displayed in text boxes on same form"
Me.BookingTableAdapter.Fill(Me.NewBookingDataSet1.Booking) "Booking is displayed in data gridview"

my text fields automatically filled when forms get loaded . i dont want to show any thing when the form gets loaded. instead i want my textboxes and datagridview to be shown empty to insert new records.
at the moment i can only get my form ready by clicking the add button on binding navigator.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.