Combobox and Database
-
Hello! I have a combobox with autocomplete, and I linked this combobox with data bindings to a database. Now I want that when I choose an item to automatically go to that record in database and display the information on screen. How do I make this, to go to that record in database? PLEASE HELP ME! Thank you! Bye!
-
Hello! I have a combobox with autocomplete, and I linked this combobox with data bindings to a database. Now I want that when I choose an item to automatically go to that record in database and display the information on screen. How do I make this, to go to that record in database? PLEASE HELP ME! Thank you! Bye!
Create two data adapters. One with just the displayed and key field or unique field selected. And another with all the fields selected and in the key field or unique field under criteria put a "=?" no quotes. Then create datasets for both. Then you need to create Functions either in a component module or just in your forms code. They could look something like this. This is from a component *************************************************************************** Public Function getdataset(ByVal strValue As String) As DataSet 'fill the dataset DsGuests1.Clear() daGuests.SelectCommand.Parameters("Phone").Value = strValue NOTE:The "Phone" parameter will just be your unique field daGuests.Fill(DsGuests1) Return DsGuests1 End Function Public Function GetNames() As DataView 'fill the dataset daNames.Fill(DsNames1) Return dvNames End Function *************************************************************************** Then you are going to have to set up the combo box to get the displayed names by calling your dataset and putting it into a dataview object with just the displayed field as the Display Member and the Unique key field as data member when the form loads. Could look something like this. *************************************************************************** Dim dvnames As DataView dvnames = mobjguests.GetNames With Combobox1 .DataSource = dvnames .DisplayMember = "FullName" .ValueMember = "Phone" .SelectedIndex = -1 End With NOTE: mobjguests was the name of my component it would be just a procedure of getnames if you were using the form and would just be dvnames = GetNames *************************************************************************** After the names are filled in the list and you then need to set up a Combobox indexChanged event. This will call the dataset with all of the fields in it and will send the data member part of your combobox to the function. After this you are going to have to bind each of you data fields to a textbox or whatever you choice and all of this will looks something like this. *************************************************************************** Private Sub cboNames_SelectedIndexChan