Click here to Skip to main content
15,071,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Two situations:
1) I add a new record and Select ISBN from the combobox. SelectedIndexChanged should fire and populate the BookName from the DataBase. It works and fine.

2) After initial loading of all data in Form, when I navigate from Record 1 to Record 2 etc, SelectedIndexChanged fires and populates BookName from the DataBase. But, this is not desirable.

How to identify and distinguish New Record from the Fetched Record, based on which these actions be controlled?

What I have tried:

VB
Private Sub ISBNComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ISBNComboBox.SelectedIndexChanged
        Dim lISBN As String
        lISBN = ISBNComboBox.Text
        PopulateBookName() 'When ISBN is changed, Book Title should be updated
    End Sub
Posted
Updated 1-Nov-18 19:14pm
v2
Comments
Bryian Tan 1-Nov-18 12:07pm
   
You might need to wrap the code in the if not postback. Example

If Not Page.IsPostBack Then 
  PopulateBookName()
End

You need to show us how your PopulateBookName() method was doing. Essentially, you just need to update your SQL query to get the latest record by doing either:

SQL
SELECT TOP 1 * FROM [TABLENAME] ORDER BY id DESC


You can also use the Posted Date to get the latest record. That really depends on you.
   
v2
Book Name is a dependent field. Based on ISBN number, book name is populated. That is all.

The issue is: When I add NEW Records, based on the ISBN, Book name is to be populated.
But, when I QUERY the existing records from the DataBase, the fetched ISBN should trigger the SelectedIndexChanged procedure and should not populate the Book Name. Otherwise, it marks the record as edited record, and prompts for saving.
   
Comments
Richard Deeming 2-Nov-18 11:26am
   
If you want to reply to a solution, click the "Have a Question or Comment?" button under that solution.

DO NOT post your reply as a new "solution".

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900