c# - Code runs but doesn't update database -


this code supposed save values in textboxes specific row. code runs fine no hiccups, refuses update database no matter do.

try {     using (var con = new oledbconnection())     {         con.connectionstring = @"provider=microsoft.ace.oledb.12.0;data source=c:\users\user\desktop\esoft\gym\gym\bin\debug\clients.accdb;";         con.open();          using (var com = new oledbcommand())         {              com.connection = con;              com.commandtext = "update gym set bmi = @bmi , health = @health , weight_change_to_healthy_bmi = @weight id = @id";               com.parameters.addwithvalue("@bmi", bmi.text);              com.parameters.addwithvalue("@health", health.text);              com.parameters.addwithvalue("@weight", change.text);              com.parameters.addwithvalue("@id", id.text);               com.executenonquery();          }      }       messagebox.show("saved");  }  catch (exception ex)  {      messagebox.show("not saved: " + ex.message);  } 

any appreciated.

as alex mentioned, set part needs , instead of and multiple columns.

check update syntax1;

update table_name set column1=value1,column2=value2,... some_column=some_value; 

but wanna few things more;

  • don't use addwithvalue as can. it may generate unexpected , surprising results sometimes. use add method overload specify parameter type , it's size.
  • open connection before execute command. means, should open connection before executenonquery line.
  • based on it's name, id column should numeric value instead of character. consider change it's type or consider change it's column name refers character typed column name.

1: i know know.. w3school link


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -