i have problem in application developing.
i insert 4 data fieldslets call them ("age", "gender" , "name", "tel") in mysql database. 99% of time work 100% once in while odd.
row 1 have age , gender, "null" , "null" , row 2 have "null" , "null" , name , tel insert 1 line of data 2 rows.
below sample of code:
string constring = configurationmanager.connectionstrings["server"].connectionstring; string query = "insert db.table (name , surname , id , tel) values('" + this.textbox1.text + "' , '" + this.textbox2.text + "' , '" + this.textbox6.text + "' , '" + this.textbox4.text + "');"; mysqlconnection condatabase = new mysqlconnection(constring); mysqlcommand cmddatabase = new mysqlcommand(query, condatabase); mysqldatareader myreader; condatabase.open(); try { myreader = cmddatabase.executereader(); while (myreader.read()) { } condatabase.close(); } catch (exception ex) { messagebox.show(ex.message); } messagebox.show("cleint details has been added system"); } if can think of reason please help. did check environment (network connection etc.) fine.
it possible there values in text box affecting insert statement. better if used parameterised statements. e.g.:
string query = "insert db.table (name , surname , id , tel) values(@param1, @param2 , @param3 , @param4);"; mysqlconnection condatabase = new mysqlconnection(constring); mysqlcommand cmddatabase = new mysqlcommand(query, condatabase); //add paramter values cmddatabase.parameters.addwithvalue("@param1", this.textbox1.text); cmddatabase.parameters.addwithvalue("@param2", this.textbox2.text); cmddatabase.parameters.addwithvalue("@param3", this.textbox6.text); cmddatabase.parameters.addwithvalue("@param4", this.textbox4.text);
Comments
Post a Comment