ms access - update data with 2 keys using oledb in c# -


i made project in c# , connected database 2 tables. first table tcostumers costumer's details, works perfectly. second table treports reports of every costumer every year. keys cid , cyear. succeeded making button insert new year costumer. problem making update button update cinfo. there no error when run program doesn't save info. here code:

 private void button2_click(object sender, eventargs e)     {             oledbcommand command = new oledbcommand(@"update treports                                                 set cinfo = @cinfo                                                     cid = @cid,                                                           cyear = @cyear", connect);              command.parameters.addwithvalue("@cinfo", textbox2.text);             command.parameters.addwithvalue("@cid", textbox3.text);             command.parameters.addwithvalue("@cyear", textbox1.text);              try             {                 connect.open();             }             catch (exception expe)             {                 messagebox.show(expe.source);             }             try             {                 command.executenonquery();              }             catch (exception expe)             {                 messagebox.show(expe.source);             }                         {                 connect.close();             }     } 

see: issue in updating ms access records using oledbcommand.executenonquery(), result not updating

the issue oledbcommand's not support named parameters:

replace:

command.parameters.addwithvalue("@cinfo", textbox2.text); command.parameters.addwithvalue("@cid", textbox3.text); command.parameters.addwithvalue("@cyear", textbox1.text); 

with:

command.parameters.addwithvalue("?", textbox2.text); command.parameters.addwithvalue("?", textbox3.text); command.parameters.addwithvalue("?", textbox1.text); 

i operate on as/400 @ work utilizes oledbcommand's, , trust me when biggest pain in arse i've ever dealt with. , of our tables have 10+ keys.


Popular posts from this blog