c# - Access database syntax error in update into statement -
first of know password reserved type of access database. have read post can put [password] , work. not working. have tried many ways , still, hope 1 help.
oledbcommand cmd = new oledbcommand(); try { string query = "update [employe] set [username] ='" + txtnewuser.text +"', [password] ='"+ txtnewpass.text + "', [authorization] ='" + nudauthorizationlvl.value + "', [id] = '" + int.parse(txtexistingid.text); cmd.commandtext = query; cmd.connection = conn; conn.open(); cmd.executenonquery(); system.windows.forms.messagebox.show("info updated!!!"); conn.close(); } catch (exception ex) { messagebox.show("error" + ex); } { conn.close(); }
i believe have comma right before where
clause , quote before id.
also, use parameters, avoid sql injection attacks:
conn.open(); cmd.commandtext = "update [employe] set [username] =@username, [password] =@password, [authorization] =@authorization [id] = @id"; cmd.connection = conn; cmd.parameters.addrange(new oledbparameter[] { new oledbparameter("@username", txtnewuser.text), new oledbparameter("@password", txtnewpass.text), new oledbparameter("@authorization", nudauthorizationlvl.value), new oledbparameter("@id", int.parse(txtexistingid.text)) }); cmd.executenonquery();
Comments
Post a Comment