C# Update MS Acess data from code, my method doesn't work -


hi first here code:

oledbconnection conexao = new oledbconnection(); try {      oledbcommand comando = new oledbcommand();     comando.connection = conexao;     string query2 = "update utilizador set nome='" + nometextbox.text + "' , dianascimento='" + dianascimentocombobox.text + "'  ,mesnascimento='" + mesnascimentocombobox.text + "'  ,anonascimento='" + anonascimentocombobox.text + "' , altura='" + alturatextbox.text + "' , sexo='" + sexocombobox.text + "' , peso='" + pesotextbox.text + "' , codgenetica='" + codgeneticatextbox1.text + "', login='" + logintextbox.text + "'  , password='" + passwordtextbox.text + "' codutilizador= " + codutilizaor.text + "";      string id = codutilizaor.text;     string command = "update utilizador set nome= '" + nometextbox.text + "' , login= " + logintextbox.text + " codutilizador= '" + id + "'  ";     conexao.open();     conexao.close();     this.close(); } catch (exception ex) {     messagebox.show("ya" + ex); } 

i want update fields doesn´t work, saw many solutions here , in youtube none solved problem, , tried hard myself still doesn ´t work , please may mesolving problem?

you missing quote on query2:

...where codutilizador= '" + codutilizaor.text + ""; 

you have execute query executenonquery(); :

    ... comando.text=command; comando.executenonquery(); 

last not least consider using parameters, because exposed sql injection.

e.g:

string command = "update utilizador set nome= @none , login=@login codutilizador=@id";  comando.parameters.addwithvalue("@nome", nometextbox.text);  comando.parameters.addwithvalue("@login", logintextbox.text);  comando.parameters.addwithvalue("@id", id); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -