Exception: No value given for one or more required parameters in VB.NET & MS-ACCESS DB

我与影子孤独终老i 提交于 2019-12-25 04:24:52

问题


I work with an Inventory System. I have an error on my code, it says

No value given for one or more required parameters.

and the error was thrown to cmd.ExecuteNonQuery(). What does it mean? can someone help me? By the way this code is for deducting Item Quantity on Database. Sorry for my bad English.

con.Open()
Dim sqlQry As String = "UPDATE [tbl_Stocks] 
                        SET [Quantity] = [Quantity] - @QU 
                        WHERE Products='" & lbPro.Text & "'"
Using cmd As New OleDbCommand(sqlQry, con)
    cmd.Parameters.AddWithValue("@QU", lbQuan.Text)
    cmd.ExecuteNonQuery()
    con.Close()
    MsgBox("Save Successfully!")
End Using

回答1:


I don't see any flaw. Try this substitute(a little tweak sending both inputs via parameter)

con.Open()
Dim sqlQry As String = "UPDATE [tbl_Stocks] SET [Quantity] = [Quantity] - @QU " &
                       "WHERE Products=@prod"
Using cmd As New OleDbCommand(sqlQry, con)
    cmd.Parameters.AddWithValue("@QU", lbQuan.Text)
    cmd.Parameters.AddWithValue("@prod", lbPro.Text)
    cmd.ExecuteNonQuery()
    con.Close()
    MsgBox("Save Successfully!")
End Using


来源:https://stackoverflow.com/questions/38738490/exception-no-value-given-for-one-or-more-required-parameters-in-vb-net-ms-acc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!