C#: How to Search keywords in a textbox with textchanged event with mysql tables RRS feed

  • Question

  • Goal: Be able to type letters/words into a textbox, then populate info into datagridview pulling from mysql tables

    This is code i found that only works with a single table. I want to pull from multiple tables/columns.

    I am still new to coding, please try to include some comments about how the code works. 

    Much appreciated, Thanks.

    public void searchData(string valueToSearch)
                string searchQuery = "SELECT * FROM extensionlist WHERE CONCAT(`ExtID`, `Facility`, `Name`, `Extensions`, `PhoneModel`) LIKE '%" + valueToSearch + "%'";
                MySqlDataAdapter adapter = new MySqlDataAdapter(searchQuery, connection);
                DataTable table = new DataTable();
                dataGridView1.DataSource = table;


    private void SearchTextboxDG_TextChanged(object sender, EventArgs e)

    private void form1_Load(object sender, EventArgs e)


    • Moved by KareninstructorMVP Friday, April 20, 2018 5:29 PM moved from forum
    • Moved by CoolDadTx Monday, April 23, 2018 2:51 PM Winforms related
    • Moved by Stanly Fan Wednesday, May 2, 2018 1:12 AM
    Friday, April 20, 2018 4:07 PM

All replies

  • If this would go there should be a lot of redundancy in your database.

    Which means that it would be good first to normalize your database.

    Of course there can be code made for your problem. 
    But that code will mean that later if you have more problems can throw it complete in the thrash bin. 

    However, it mainly depend on the Select string which you make. That you can better first make complete working and if that does not go, ask help in the My SQL transact SQL forum. (Not the SQLTransact forum). 

    You know this is a Microsoft forum and not an Oracle forum  (with the abuse button I've marked that you ask this in the VB forum while your code is C#, probably a moderator will move it to the correct Microsoft C# forum)


    Friday, April 20, 2018 4:18 PM
  • Hi datdereyeehaw,

    In fact, your question is more related to MySQL-selection from multiple tables, if there are associations between multiple tables, you can select the records from the multiple tables with 'Join' keyword, please refer to the following thread for more details about 'join':

    SQL query return data from multiple tables

    And there is a document would help you in MSDN:

    FROM (Transact-SQL)



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    • Edited by Stanly Fan Tuesday, April 24, 2018 2:55 AM
    Tuesday, April 24, 2018 2:54 AM