c# - I want to update my stock quantity keeping along the previous quantity. -


i want update stock quantity keeping along previous stock status. need update previous data adding or lessening depending upon inward or outward transaction. not getting stock updated in currentstock table. //this start of problem segment

        sqlcommand cmd2 = new sqlcommand("select stock currentstock itemname=@a", con);         con.open();         int x=0;         cmd2.parameters.addwithvalue("@a",combobox2.selecteditem.tostring());         sqldatareader dr = cmd2.executereader();         if (dr.read())         {              x = dr.getint16(2);         }         if (radiobutton1.checked == true)         {             x = x + convert.toint16(textbox1.text);         }         else if (radiobutton2.checked == true)         {             x = x - convert.toint16(textbox2.text);         }             con.close();            sqlcommand cmd1 = new sqlcommand("update currentstock set stock=@a itemname=@b",con);         con.open();         cmd1.parameters.addwithvalue("@a", x);         cmd1.parameters.addwithvalue("@b", combobox2.selecteditem.tostring());         cmd1.executenonquery();         con.close(); 

// end of problem segment

firstly please dont use values directly user inputs when talking sql tables (see sql injection). use stored procedures.

i expect value getting combo box not valid value in itemname column of table.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -