parameters - Update Access 2010 database in C# -
i'm going crazy that, i'm trying save changes in table in access 2010 .accdb database c#
i have method:
using (oledbconnection conn = new oledbconnection(@"provider=microsoft.ace.oledb.12.0;data source=" + frmmain.dbpath + "; persist security info=false;")) { conn.open(); using (oledbtransaction tx = conn.begintransaction()) { using (oledbcommand cmd = new oledbcommand( "update ricette set " + "ricette.resinaureicatotale = @resinaureicatotale, " + "ricette.resinaureicaparziale = @resinaureicaparziale, " + "ricette.resinamelaminicatotale = @resinamelaminicatotale, " + "ricette.resinamelaminicaparziale = @resinamelaminicaparziale, " + "ricette.acquatotale = @acquatotale, " + "ricette.acquaparziale = @acquaparziale, " + "ricette.farinettatotale = @farinettatotale, " + "ricette.farinacoccototale = @farinacoccototale, " + "ricette.componenteatotale = @componenteatotale, " + "ricette.tempomix = @tempomix " + "where ricette.[nome] = [@nome];", conn)) { cmd.commandtype = commandtype.text; cmd.transaction = tx; using (oledbdataadapter ad = new oledbdataadapter(cmd)) { try { datarow row = ds.tables[0].rows.find(cmbincollaggio.selecteditem.tostring()); string[] ric = new string[1]; switch (cmbincollaggio.selecteditem.tostring()) { case "if20": cmd.parameters.add("@nome", oledbtype.varchar, 100, "nome").value = "if20"; cmd.parameters.add("@resinaureicatotale", oledbtype.varchar, 100, "resinaureicatotale").value = rutedit.text; frmmain.seriale.datawrite("00wd", rutedit.text, 2100); ric = frmmain.seriale.dataread("00rd", 2100, 1); rutlabel.text = convert.toint32(ric[0]).tostring(); cmd.parameters.add("@resinaureicaparziale", oledbtype.varchar, 100, "resinaureicaparziale").value = rupedit.text; frmmain.seriale.datawrite("00wd", rupedit.text, 2101); ric = frmmain.seriale.dataread("00rd", 2101, 1); ruplabel.text = convert.toint32(ric[0]).tostring(); cmd.parameters.add("@resinamelaminicatotale", oledbtype.varchar, 100, "resinamelaminicatotale").value = rmtedit.text; frmmain.seriale.datawrite("00wd", rmtedit.text, 2102); ric = frmmain.seriale.dataread("00rd", 2102, 1); rmtlabel.text = convert.toint32(ric[0]).tostring(); cmd.parameters.add("@resinamelaminicaparziale", oledbtype.varchar, 100, "resinamelaminicaparziale").value = rmpedit.text; frmmain.seriale.datawrite("00wd", rmpedit.text, 2103); ric = frmmain.seriale.dataread("00rd", 2103, 1); rmplabel.text = convert.toint32(ric[0]).tostring(); cmd.parameters.add("@acquatotale", oledbtype.varchar, 100, "acquatotale").value = atedit.text; frmmain.seriale.datawrite("00wd", atedit.text, 2104); ric = frmmain.seriale.dataread("00rd", 2104, 1); atlabel.text = convert.toint32(ric[0]).tostring(); cmd.parameters.add("@acquaparziale", oledbtype.varchar, 100, "acquaparziale").value = apedit.text; frmmain.seriale.datawrite("00wd", apedit.text, 2105); ric = frmmain.seriale.dataread("00rd", 2105, 1); aplabel.text = convert.toint32(ric[0]).tostring(); cmd.parameters.add("@farinettatotale", oledbtype.varchar, 100, "farinettatotale").value = ftedit.text; frmmain.seriale.datawrite("00wd", ftedit.text, 2106); ric = frmmain.seriale.dataread("00rd", 2106, 1); ftlabel.text = string.format("{0,0}", convert.toint32(ric[0]) / 10); cmd.parameters.add("@farinacoccototale", oledbtype.varchar, 100, "farinacoccototale").value = fctedit.text; frmmain.seriale.datawrite("00wd", fctedit.text, 2107); ric = frmmain.seriale.dataread("00rd", 2107, 1); fctlabel.text = string.format("{0,0}", convert.toint32(ric[0]) / 10); cmd.parameters.add("@componenteatotale", oledbtype.varchar, 100, "componenteatotale").value = catedit.text; frmmain.seriale.datawrite("00wd", catedit.text, 2108); ric = frmmain.seriale.dataread("00rd", 2108, 1); catlabel.text = string.format("{0,0}", convert.toint32(ric[0]) / 10); cmd.parameters.add("@tempomix", oledbtype.varchar, 100, "tempomix").value = tmedit.text; frmmain.seriale.datawrite("00wd", tmedit.text, 2109); ric = frmmain.seriale.dataread("00rd", 2109, 1); tmlabel.text = convert.toint32(ric[0]).tostring(); break; } ad.updatecommand = cmd; ds.acceptchanges(); ad.update(ds); tx.commit(); } catch (exception ex) { tx.rollback(); messagebox.show("salvataggio non riuscito.\n" + ex.message, "", messageboxbuttons.ok, messageboxicon.exclamation); } } } } conn.close(); }
this code don't works... works in dataset, changes not copied in original database... find errors? thank help...
solved!!!
just add
cmd.executenonquery();
and remove dataadapter
object.
Comments
Post a Comment