Update Query Is Not Working In VB.NET With MS Access -
imports system.data.oledb
public class form1
this connection string
dim con new oledbconnection("provider=microsoft.ace.oledb.12.0;data source=|datadirectory|store.accdb") private sub picturebox1_click(byval sender system.object, byval e system.eventargs) handles picturebox1.click con.open() dim cmd new oledbcommand("select [qty other], [hqty pl3], [hqty pl5], [total qty] from(material)where ([mat code] = @a)", con) cmd.parameters.addwithvalue("@a", textbox1.text) dim dr oledbdatareader = cmd.executereader dim qtyotherm, hqtypl3m, hqtypl5m, totalqtym new double dim qtyotherr, rqtypl3r, rqtypl5r, qtyr new double dim totalqtyfinal new double dim cmdins new oledbcommand("insert recept ([mat code], qty, rate, taxes, [rqty pl3], [rqty pl5], [rqty other]) values (@b, @c, @d, @e, @f, @g, @h)", con) cmdins.parameters.addwithvalue("@b", textbox1.text) cmdins.parameters.addwithvalue("@c", textbox2.text) cmdins.parameters.addwithvalue("@d", textbox10.text) cmdins.parameters.addwithvalue("@e", textbox9.text) cmdins.parameters.addwithvalue("@f", textbox3.text) cmdins.parameters.addwithvalue("@g", textbox4.text) cmdins.parameters.addwithvalue("@h", textbox5.text) dim checkinsert new integer checkinsert = cmdins.executenonquery
this execute non query working properly
if checkinsert > 0 if dr.hasrows while dr.read qtyotherm = dr(0) hqtypl3m = dr(1) hqtypl5m = dr(2) totalqtym = dr(3) end while
the text box showing addition vale
totalqtyfinal = totalqtym + textbox2.text textbox15.text = totalqtyfinal messagebox.show("chk text box value")
problem starts here
dim cmdupdate new oledbcommand("update material set [total qty] = @j ([mat code] = @i)", con) cmdupdate.parameters.addwithvalue("@i", textbox1.text) cmdupdate.parameters.addwithvalue("@j", textbox15.text) dim chkupdate new integer chkupdate = cmdupdate.executenonquery if chkupdate > 0 messagebox.show("update done :) ")
always else statement message shown
else messagebox.show("fail update :(") end if messagebox.show("quer 1 , 2 executed") else messagebox.show("dr not working.") end if else messagebox.show("insert query fail") end if con.close() end sub
end class
see this answer. oledbcommand not support named parameters. need add parameters in same order have them in within sql statement.
in update statement, have @j followed @i, , you're adding @i followed @j. oledbcommand sees ? followed ? in sql statement, , when add parameters, adds parameter 1 followed parameter 2.
Comments
Post a Comment