c# - update stock quantity keeping along the previous quantity -


i having problem updating database stock. want add stock previous stock available in inventory error check mysql syntax before where. , query.

"update tblproducts set quantity=quantity+'"+txtaddqty.text+"' productid='"+txtproductid.text+"' " 

where wrong.

you concatenating quantity , string (txtaddqty.text)

"update tblproducts set quantity = quantity + " + convert.toint32(txtaddqty.text) +  " productid='" + txtproductid.text + "'" 

caution

  1. above sql statement fails if txtaddqty.text gives alphabets instead of numeric value.
  2. also fail if txtproductid.text gives unexpected value
  3. not recommended way of doing things database application.

instead of making sql statement string concatenation should use parametrized sql query. doing prevent of sql injection problem.


Comments

Popular posts from this blog

Ansible warning on jinja2 braces on when -

Parsing a protocol message from Go by Java -

javascript - Replicate keyboard event with html button -