Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a C# Windows form that uses a MS Access database as the data source. The code that does not work is
C#
private void txtSearchName_TextChanged(object sender, EventArgs e)
        {
            string srch = txtSearchName.Text + "%";
            MessageBox.Show(srch);
            this.contactsTableAdapter.FillByName(this.contact_management_databaseDataSet.Contacts, srch, srch);

        }

Nothing is triggered from the textbox change. Can someone show me how to correct this? The query works correctly in the query designer.
I use the same code with MySql and it works as it should.

What I have tried:

I've tried everything I know without success.
Posted
Updated 17-Aug-21 6:46am
v2

If nothing is triggered - including the message box - then your event handler is not wired up properly.

If the message box shows, but the query doesn't execute, then there's something wrong in the table adapter, which we can't see.

If the query executes but doesn't return any records, then there's something wrong with your query, or there are no matching records. We can't tell you which, because we can't see your query or your input value, and we don't have access to your database.
 
Share this answer
 
Comments
BobbyStrain 17-Aug-21 12:42pm    
Nothing is triggered. The message does not show. But the query is good. I'll delete the textbox and code, and rebuild. Maybe that will work. I added the textbox to the form, but pasted the code from a working application. So, maybe it didn't get wired properly.
Richard Deeming 17-Aug-21 12:43pm    
You need to use the "events" tab of the properties window for the textbox to wire up the event handler.
How to add or remove an event handler - Windows Forms .NET | Microsoft Docs[^]
Quote:
Nothing is triggered. The message does not show.

Then the event handler is not correctly hooked up to the TextBox, or you are entering data in the wrong textbox (or wrong instance of the right textbox)

Start with the debugger: put a breakpoint on the first lien of the handler and check if it is hit. If it isn't, find every reference to the TextBox and put a breakpoint on all of those too. When you find out which reference isn't working as expected you can start fixing teh problem.

But we can't do any of that for you!
 
Share this answer
 
Comments
BobbyStrain 17-Aug-21 12:53pm    
The resolution was simple. It was a wiring problem. I deleted the event handler then created a new one by double-click on the textbox on the form. So the designer properly added the event handler. Thank you all for your prompt response.

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