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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -