2014-04-05 26 views
0

此查詢下面是用來將數據插入到數據庫減法MySQL的VB網

msql = "update tb_temp set qty = qty + '" & Trim(txtStock.Text) & "' where product_id='" & Trim(cbProductID.Text) & "' " 

它工作得很好,並運行另外的功能像它應該是

,但是當我改變算術運算符成-減法

msql = "update tb_temp set qty = qty - '" & Trim(txtStock.Text) & "' where product_id='" & Trim(cbProductID.Text) & "' " 

其返回unchandled例外,這樣

A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll 

有人可以解釋這一點嗎?之前由於

+0

你應該使用選項strict ... always。 'qty = qty - '「&Trim(txtStock.Text)'正在用一個字符串(文本)對一個數字進行數學運算。 – Plutonix

+0

你能給我一個例子嗎?我應該在我的連接字符串中使用option strict? –

+0

i我已經修好了..非常感謝plutonix ..事實證明,我不需要額外的單引號..hahaha –

回答

0

由我自己定吧..事實證明,我使用了太多的單引號:)

msql = "update tb_temp set qty = qty - '" & Trim(txtStock.Text) & "' where product_id='" & Trim(cbProductID.Text) & "' " 

msql = "update tb_temp set qty = qty - " & Trim(txtStock.Text) & " where product_id='" & Trim(cbProductID.Text) & "' " 

我刪除單引號之前" &它工作!