[英]How to pass an Informix Collection Parameter (LIST, SET, MULTISET) in c# through an ODBC Connection
I'm looking for a way to pass an Informix List Parameter in C#. 我正在寻找一种在C#中传递Informix列表参数的方法。
I asked a previus question of How to pass a multi value parameter to Informix, but now I need to execute it from C#. 我问了一个关于如何将多值参数传递给Informix的问题,但是现在我需要从C#执行它。
The related question is here . 相关问题在这里 。
In resume I have a procedure like this. 在简历中,我有一个这样的程序。
CREATE PROCEDURE test_3(c LIST(CHAR(10) NOT NULL))
RETURNING CHAR(10) AS r;
DEFINE r CHAR(10);
FOREACH SELECT * INTO r FROM TABLE(c)
RETURN r WITH RESUME;
END FOREACH;
END PROCEDURE;
It works fine executing it in Aqua Data Studio.8.0.22 like this 像这样在Aqua Data Studio.8.0.22中执行它可以正常工作
EXECUTE PROCEDURE test_3('LIST{''stspols'',''stsrepo''}');
So I made a quick example of how executing it in c#. 因此,我举了一个简短的示例说明如何在c#中执行它。
First like a CommandType.Text
首先像
CommandType.Text
string strParameters = "LIST{''stspols'',''stsrepo''}";
using (OdbcConnection oConnection = new OdbcConnection("DSN=MYDSN;UID=MYUID;PWD=MYPWD;"))
{
oConnection.Open();
using (OdbcDataAdapter oCommand = new OdbcDataAdapter(string.Format("EXECUTE PROCEDURE test_3('{0}')", strParameters), oConnection))
{
using (DataTable dt = new DataTable())
{
oCommand.Fill(dt);
}
}
}
This one works FINE. 这个作品很好。
So I got courious and tried to execute it but as CommandType.StoredProcedure
所以我很好奇并尝试执行它,但是作为
CommandType.StoredProcedure
string strParameters = "LIST{''stspols'',''stsrepo''}";
using (OdbcConnection oConnection = new OdbcConnection("DSN=MYDSN;UID=MYUID;PWD=MYPWD;"))
{
oConnection.Open();
using (OdbcCommand oCommand = new OdbcCommand("{CALL test_3(?)}", oConnection))
{
oCommand.CommandType = CommandType.StoredProcedure;
OdbcParameter oParameter = new OdbcParameter("c", OdbcType.Char, 4000);
oParameter.Value = strParameters;
oCommand.Parameters.Add(oParameter);
using (OdbcDataAdapter oDataAdapter = new OdbcDataAdapter(oCommand))
{
using (DataTable dt = new DataTable())
{
oDataAdapter.Fill(dt);
}
}
}
}
But now I get ERROR [HY000] [Informix][Informix ODBC Driver][Informix]Invalid collection literal value.
但是现在我得到了
ERROR [HY000] [Informix][Informix ODBC Driver][Informix]Invalid collection literal value.
So after all of this, my final question is 所以所有这些之后,我的最后一个问题是
How I can execute this kind of Informix procedures from C#, with a Collection parameter Type (LIST, SET, MULTISET) as a Stored Procedure. 如何使用C参数将Collection参数类型(LIST,SET,MULTISET)作为存储过程从C#执行这种Informix过程。
Apparently I'm doing something wrong. 显然我做错了。
Thanks in advance for your valuable help. 在此先感谢您的宝贵帮助。
The doubled-up single quotes were necessary in raw SQL, but should not be needed in the parameterized query. 在原始SQL中,加倍的单引号是必需的,但在参数化查询中则不需要。 You should be able to replace:
您应该能够替换:
string strParameters = "LIST{''stspols'',''stsrepo''}";
with: 有:
string strParameters = "LIST{'stspols','stsrepo'}";
Understanding when quotes need to be doubled and when they don't is tricky, but 'not in placeholder values' is accurate. 了解何时需要将引号加倍,何时不加引号是很棘手的,但是“不在占位符值中”是准确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.