0

Please I have an autocomplete textbox which fetches value from a tabe in the database. But after i choose the name i want to get the id of the value selected and save it in the database. Am using mysql and c#.

using (MySqlConnection con = new MySqlConnection(MyConString))
            {
                connection.Open();
                string command = "select * from suppliers";
                MySql.Data.MySqlClient.MySqlCommand myCommand = new MySql.Data.MySqlClient.MySqlCommand(command, connection);
                MySqlDataReader reader = myCommand.ExecuteReader();

                AutoCompleteStringCollection MyCollection = new AutoCompleteStringCollection();
                while (reader.Read())
                {
                 MyCollection.Add(reader["Name_of_Supplier"].ToString());

                }

                txtSupplier.AutoCompleteCustomSource = MyCollection;

                connection.Close();
            }
3
Contributors
7
Replies
35
Views
1 Month
Discussion Span
Last Post by Marlon189
0

I worry your question was not worded well. Your topic question is "Get id of autocomplete textbox in c# windows form" so in the code provided the id or name of the control appears to be txtsupplier. If that's incorrect, just click once on the object you have on screen in the designer view and get its name/id there.

0

Sorry @rproffitt . What i mean was after i select the suggested element from the db i have a hidden text box that get filled with the id of the selected element. say txtsup_id. Your help will be really appreciated. Thnx

0

Still unclear. You state "i have a hidden text box that get filled with the id of the selected element. say txtsup_id." So you have that and you have the name of the source object so the question to me is not any clearer.

0

look at it like a combo box. which has the id and text(diplaymember and display value). buh this time in a textbox situation

0

If I understand your question correctly, you can use a query like
query = String.Format("select ID from suppliers where Name_of_Supplier = {0}", txtSupplier.Text);
that should return the id

0

So should i do another query after my first query. Or i should replace this with the my query. Thanks

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.