使用输出参数从 Informix 检索值
我需要使用输出参数对 Informix 数据库执行查询来检索所需的值。我已经尝试了该查询的许多不同变体,但到目前为止没有一个起作用。我在文档中看到的唯一示例使用存储过程来获取结果,但在这种情况下,存储过程不是一个选项。
我想做的相关代码是:
DB2Connection con = new DB2Connection(ConStr);
DB2Command cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select ? = Column1 from Table1 where Table1.serial = 1";
cmd.Parameters.Add("param", DB2Type.Integer).Direction = ParameterDirection.Output;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
object o = cmd.Parameters["param"].Value;
这与我对 SQL Server 使用的查询相同,因为我不确定
我正在使用的 Informix 语法是否正确:
Visual Studio 2010
.NET框架2.0
Informix 11.5(DB2 驱动程序,IBM.Data.DB2.dll)
与我为 Oracle 和 MS SQL Server 工作的方法相同,通过更改查询并使用相应的 ado.net 驱动程序
Oracle:
cmd.CommandType = CommandType.Text;
cmd.CommandText = "BEGIN select Column1 INTO :param from Table1 where Table1.serial = 1; END;";
cmd.Parameters.Add(":param ", OracleDbType.Int32).Direction = ParameterDirection.Output;
SQL Server:
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT @param = Column1 from Table1 where Table1.serial;";
cmd.Parameters.Add("@param", SqlDbType.Int).Direction = ParameterDirection.Output;
有谁知道是否这可以在 informix 中实现而不使用存储过程吗? cmd.ExecuteScalar();也不是一个选项,因为正在使用的框架需要使用输出参数。
I need to execute a query against an Informix database using output parameters to retrieve the desired value. I’ve tried many different variants of the query, but so far none has worked. The only examples I’ve seen in the documentations have used stored procedures to get the result but a stored procedure is not an option in this case.
The relevant code from what I’m trying to do is:
DB2Connection con = new DB2Connection(ConStr);
DB2Command cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select ? = Column1 from Table1 where Table1.serial = 1";
cmd.Parameters.Add("param", DB2Type.Integer).Direction = ParameterDirection.Output;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
object o = cmd.Parameters["param"].Value;
This is with the same query as I use against SQL Server as I'm not sure of the correct syntax for Informix
I’m using:
Visual Studio 2010
.NET Framework 2.0
Informix 11.5 (DB2 driver, IBM.Data.DB2.dll)
The same method that I’ve got working for Oracle and MS SQL Server by changing the query and using their corresponding ado.net driver
Oracle:
cmd.CommandType = CommandType.Text;
cmd.CommandText = "BEGIN select Column1 INTO :param from Table1 where Table1.serial = 1; END;";
cmd.Parameters.Add(":param ", OracleDbType.Int32).Direction = ParameterDirection.Output;
SQL Server:
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT @param = Column1 from Table1 where Table1.serial;";
cmd.Parameters.Add("@param", SqlDbType.Int).Direction = ParameterDirection.Output;
Does anyone know if this is possible with informix without the use of stored procedures?
cmd.ExecuteScalar(); is not an option either because the framework that is being used requires the use of output parameters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论