MySQL Connector/NET Output Parameter Returning NULL

依然范特西╮ 提交于 2019-12-10 19:51:23

问题


Using the following code:

MySqlParameter curParam = new MySqlParameter("var", MySqlDbType.Int32);
curParam.Direction = System.Data.ParameterDirection.Output;
oCmd.Parameters.Add(curParam);

With the following Stored Procedure:

CREATE PROCEDURE testProc(OUT var INT)
BEGIN
    SELECT 1, 2, 3;
    SELECT 27 INTO var;
END
$$

Running this from the console returns "27":

CALL testProc(@i);
SELECT @i;

However in .NET, when executing the query (when the connection is still open), curParam.value returns NULL.

The stored procedure otherwise returns the correct results. Additionally, when running the Stored Procedure directly in the console, the output param returns correctly as well.

Am I missing something?


回答1:


output parameters will only be populated after the reader is closed. when does your code execute the reader compared to when you get the parameter value?



来源:https://stackoverflow.com/questions/20789217/mysql-connector-net-output-parameter-returning-null

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