Click here to Skip to main content
14,116,626 members
Rate this:
 
Please Sign up or sign in to vote.
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
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi TextBox has TextChanged event,when the TextChanged trigger,can invoke again the method.
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

logic in Text Changed event does
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190518.1 | Last Updated 9 Apr 2015
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100