使用vb.net在集合中找不到MySql存储过程参数

时间:2016-04-19 15:03:44

标签: mysql vb.net stored-procedures

我正在尝试执行并调用我创建的存储过程。在调用存储过程时,它会抛出错误。

这是我的存储过程:

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_SalesInsertNewOrder`(   
   IN spTransNo INT,
   IN spProdId INT,
   IN spProdOPrice double,
   IN spProdNPrice double,
   IN spProdQty INT, 
   IN spAmount double,
   IN spRemarks varchar(45),
   OUT spStdID INT
)

BEGIN
    INSERT INTO tbl_salestransactiondetail(std_TransNo, std_ProdID, std_OPrice, std_NPrice, std_QtySold, std_AmountSold, std_Remarks) 
    VALUE(spTransNo, spProdId, spProdOPrice, spProdNPrice, spProdQty, spAmount, spRemarks);
    SELECT max(std_PK) INTO spStdID from tbl_salestransactiondetail;    
END

这是我的vb.net代码:

Dim comm As MySqlCommand
        Try                
            connectToDB()
            comm = New MySqlCommand("sp_SalesInsertNewOrder", conn)
            comm.CommandType = CommandType.StoredProcedure
            comm.Parameters.AddWithValue("@spTransNo", modCurTransNum)
            comm.Parameters.AddWithValue("@spProdId", std_ProdId)
            comm.Parameters.AddWithValue("@spProdOPrice", std_ProdOPrice)
            comm.Parameters.AddWithValue("@spProdNPrice", std_ProdNPrice)
            comm.Parameters.AddWithValue("@spProdQty", std_ProdQty)
            comm.Parameters.AddWithValue("@spAmount", std_Amount)
            comm.Parameters.AddWithValue("@spRemarks", std_Remarks)                
            comm.Parameters("@spSTDId").Direction = ParameterDirection.Output
            If comm.ExecuteNonQuery() > 0 Then
                modCurOSNo = comm.Parameters("@spSTDId").Value
                MessageBox.Show("Order has been successfully ADDED!", "Sales Transaction", MessageBoxButtons.OK, MessageBoxIcon.Information)

            End If
            conn.Close()
        Catch ex As MySqlException
            MessageBox.Show("Error on modInsertNewOrder() function : " & ex.Message, "Sales Transaction", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Finally
            conn.Dispose()
        End Try

错误来自这一行:

comm.Parameters("@spSTDId").Direction = ParameterDirection.Output
  

参数' @spSTDId'没有在集合中找到。

你可以帮我解决一下吗?谢谢。

0 个答案:

没有答案