Click here to Skip to main content
15,351,641 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Want to popolate text box fields on text change using connection string c#. When I enter an key field it should retrieve info for that record from the database and display it on the form text boxes

What I have tried: function to read from a selected record
Updated 30-Jan-22 19:38pm

Not enough information given to explain what you're using, how you are implementing, etc... Are you using Angular, Vue, React, Blazor, razor, etc...

Please read the following before updating your question or posting future questions:
* CodeProject Quick Answers FAQ
* Posting Guidelines for Asking Questions
* How do I improve my question?
On Keypress event you can implement the below code but this is not a good approach because
on every keyPress you are hitting the database which cause your application performance.
If you really want to do this then can apply this change on Textbox leave event or provide a button to check from database. Use the following code to achieve:
SqlConnection sqlConn = new SqlConnection(ConnectionString);
SqlCommand sqlComd = new SqlCommand("StoreProcedure", sqlConn);
sqlComd.Parameters.Add("@Name", SqlDbType.VarChar).Value = textBox.text;
SqlDataReader dataReader = sqlComd.ExecuteReader();
if (DR1.Read())
    // Change according to your returned value
    textBox.Text = dataReader.GetValue(0).ToString(); 

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