-1

I am having problem updating my database with stock. I want to add stock to the previous stock that is available in the inventory but error say that check your mysql Syntax before WHERE. and this is my query.

"UPDATE tblproducts SET Quantity=Quantity+'"+txtAddQty.Text+"' WHERE ProductId='"+txtProductId.Text+"' "

Where am i wrong. Help

Guy
  • 46,488
  • 10
  • 44
  • 88
  • 1
    You want to add a `string` to a quantity? That seems wrong. I'd expect `Quantity` to be some kind of numerical value. -- also: *please* read about SQL injection attacks. Your code is wide open for that. Use SQL parameters instead. – Corak Jul 26 '17 at 06:48

4 Answers4

1

imho, Quantity=Quantity+'"+txtAddQty.Text+"' will not work.

you need to remove those ' since you would add a varchar to an int

edit: You also could use a debugger to check the output of your string.

1

I guess Quantity is numeric, so you should remove the apostrophes ' in your string.

And please do not generate SQL-queries with string concatenation.
Use parameterized queries: How do I create a parameterized SQL query? Why Should I?

MatSnow
  • 7,357
  • 3
  • 19
  • 31
1

You are concatenating Quantity and String (txtAddQty.Text)

"UPDATE tblproducts SET Quantity = Quantity + " + Convert.ToInt32(txtAddQty.Text) + 
" WHERE ProductId='" + txtProductId.Text + "'"

Caution

  1. Above SQL Statement fails if txtAddQty.Text gives alphabets instead of numeric value.
  2. Also will fail if txtProductId.Text gives unexpected value
  3. Not recommended way of doing things with database from application.

Instead of making sql statement by string concatenation you should use parametrized sql query. Doing so will prevent some of the sql injection problem.

Bhuban Shrestha
  • 1,304
  • 11
  • 27
-1

Try removing the single quotes as you are trying to add it as a number. Only use quotes for strings.

Example:

UPDATE tblproducts SET Quantity=Quantity+"+txtAddQty.Text+" WHERE ProductId='"+txtProductId.Text+"' "
vylor
  • 11
  • 4