textbox value change in c# -
if textbox value has changed, how can select database new textbox value , not old value?
string constring = "datasource=127.0.0.1;username=root;password=admin"; string query = "select * mohamed.usercompany1 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); }
you can add handler textchanged
event. raised when text changed.
private void textbox1_textchanged(object sender, eventargs e) { //textbox1.text contains new text //execute sql... }
but should careful. possible input sql statement in textbox, damages database. more secure use parameters:
parameterized query mysql c#