的MySQL Connector / NET输出参数返回NULL [英] MySQL Connector/NET Output Parameter Returning NULL

查看:140
本文介绍了的MySQL Connector / NET输出参数返回NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的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
$$

从控制台返回27运行这样的:

Running this from the console returns "27":

CALL testProc(@i);
SELECT @i;

然而,在.NET中,执行查询时(连接仍然是开放的),curParam.value返回NULL。

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.

我缺少的东西?

推荐答案

输出参数才会被填充后,读者可以关闭。什么时候你的code执行读写器相比,当你得到的参数值?

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?

这篇关于的MySQL Connector / NET输出参数返回NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆