在集合中找不到 MySQL 参数

标签 mysql vb.net

我在尝试使用参数更新 MySQL 值时遇到了困难。 我想我可以排除打字错误。

我收到错误“在集合中找不到参数@inout_price”。

谁能告诉我哪里出错了?

   Using nCmdUp As MySql.Data.MySqlClient.MySqlCommand = g_CnWebDB.CreateCommand
                    With nCmdUp
                        .CommandText = "UPDATE payinout SET inout_price=@inout_price WHERE inout_guid=@inout_guid"
                        Dim sNewPrice As String = "53.55"
                        .Parameters("@inout_price").Value = sNewPrice'In this line the error is thrown
                        .Parameters("@inout_guid").Value = sGUID
                        .ExecuteNonQuery()
                        End
                    End With

                End Using

谢谢!

最佳答案

参数应添加到参数集合中。

 Using nCmdUp As MySqlCommand = g_CnWebDB.CreateCommand
     With nCmdUp
        .CommandText = "UPDATE payinout SET inout_price=@inout_price " & _
                       "WHERE inout_guid=@inout_guid"
        Dim sNewPrice As String = "53.55"
        .Parameters.AddWithValue("@inout_price", sNewPrice)
        .Parameters.AddWithValue("@inout_guid", sGUID)
        .ExecuteNonQuery()
     End With
 End Using

您可以使用快捷方式 AddWithValue (对于 Sql Server,但概念是相同的)添加参数及其值或使用更详细的方式 Add 。如果您想微调参数数据类型和 varchar 值的大小,那么第二种方法是更好的选择。

关于在集合中找不到 MySQL 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24441833/

相关文章:

mysql - 按同一表的前一个和下一个 fk 的两列对 MySql 查询进行排序

mysql - Percona Xtradb集群 : Error while getting data from donor node

vb.net - 在 VB.NET 中重定向事件

javascript - Sequelize : updating updatedAt manually

mysql - 触发错误mysql

MySQL JOIN 查询帮助 : join two tables with distinct right table rows ordered in descending order

.NET MVC - 如何从另一个 Controller 获取 JsonResult?

vb.net - 将 LAT LONG 坐标从字符串转换为耗时值

mysql - VB.net - 从 MySQL 获取日期,添加月份并将其与今天的日期进行比较

c# - .NET 模拟 Ctrl+Alt+Del 发送键