Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
If a textbox value has changed, how can I select from a database by the new textbox value , not the old value?
using c# and MySql
my code
C#
string constring = "datasource=127.0.0.1;username=root;password=admin";
string Query = "select * from mohamed.usercompany1 where office  =  '" + textBox1.Text + "'  ;";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
DataSet DataSet1 = new DataSet();
MySqlDataReader myReader;
try
{
    conDataBase.Open();
    myReader = cmdDataBase.ExecuteReader();
    if (myReader.Read())
    {
        string scode = myReader.GetInt32("techname").ToString();
        textBox1.Text = (string)myReader["techname"];
        comboBox2.Items.Add(scode).ToString();
        listView1.Items.Add(scode).ToString();
        this.Refresh();
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
Posted
Comments
PIEBALDconsult 9-Apr-15 22:20pm    
Please use a parameterised statement -- NEVER use concatenation to put values, especially user-entered values, in an SQL statement.

Hi TextBox has TextChanged event,when the TextChanged trigger,can invoke again the method.
 
Share this answer
 
logic in Text Changed event does
 
Share this answer
 

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