Updating Combo list after inserting new record

I have a form that has a combo box who's list has Customers.  This is bound to a data adapter during form load.  The code is:


I have a button that brings up a New Cutomer form that successfully adds a new Customer to the database.  No problem from a DB standpoint.

Once the new customer is added however, I need to refresh the Customer combo box list to show the newly added customer.  If I .Fill again, the list is appended to.

 I can't figure out how to do this, so help is appreciated.  I hope I'm using the DataAdapter & ComboBox correctly.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian CroweDatabase AdministratorCommented:
To refresh instead of append

daCustList.MissingSchemaAction = MissingSchemAction.AddWithKey
daCustList.AcceptChangesDuringFill = True
dslocumAuthor Commented:

Thanks. Your suggestion still doesn't cause my original ComboList to include the new Customer in the list, at least in my situation.  Is there another step I need to do after your code ?  


Brian CroweDatabase AdministratorCommented:
you may need to rebind your combobox to the dataadapter
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

dslocumAuthor Commented:

Still having probs.  My code is:

    Private Sub btnCustNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustNew.Click
        Dim FrmCust As New frmCustomer

            With FrmCust

                .ShowDialog()      'Add new customer to DB

                daCustList.MissingSchemaAction = System.Data.MissingSchemaAction.AddWithKey
                daCustList.AcceptChangesDuringFill = True
                cboCustName.Rebind()     'Added per your last suggestion

            End With

        Catch ex As Exception
        End Try

FYI, If I close the app and then reopen, the new Customer DOES show in the combo list.

BTW, I'm not sure if it matters, but I'm using a ComponentsOne Combo box.  I guess that this should work the same as a standard ComboBox.

I appreciate your help to hopeffuly resolve this!

Brian CroweDatabase AdministratorCommented:
the lines...

daCustList.MissingSchemaAction = System.Data.MissingSchemaAction.AddWithKey
daCustList.AcceptChangesDuringFill = True

only need to be declared once for the dataadapter so you can put them in your form.load procedure

to rebind try this...
cbocustname.databindings.add("Text", myDataSet.myDataTable, "ColumnName")

dslocumAuthor Commented:
Hello again,

I added a Watch to the C1 ComboBox, and it appears that there are no databindings, so the technique above isn't working.  When I stated my problem originally, I thought that the control was bound.  Is there some other .NET technique that is being used?

The design-time C1 control properties are set to:

DataSource = DataSet11
DataMember = ARCUSFIL_SQL    'This is the table with the appropriate SQL Select to fill the combo's list
DisplayMember = CustName
ValueMember = Cus_No

I don't necessarily expect that you know this C1 combo control, but can you recognize the technique that is used and continue to help with my goal?

Thanks for your time and patience.

Brian CroweDatabase AdministratorCommented:
everything looks the same as the standard combobox except for the DataMember property.  A standard  Combobox would look more like...

DataSource = DataSet11.tables("ARCUSFIL_SQL")
DisplayMember = "CustName"
ValueMember = "Cus_No"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.