Informix参数化odbc查询不起作用

时间:2016-10-04 04:53:11

标签: c# odbc informix parameterized-query

参数化查询未按预期工作。在c#中执行Informix ODBC命令时:

OdbcCommand oc = Connection.CreateCommand();
oc.CommandText = "SELECT COUNT(*) AS CNT, MAX(someattr) AS attr1 FROM ?";
oc.Parameters.Add(new OdbcParameter() { Value = table.Name, OdbcType = OdbcType.Char });
try
{
    OdbcDataReader or = oc.ExecuteReader(); //here the exception occurs
    ....

发生异常:ERROR [42000] [Informix] [Informix ODBC Driver] [Informix]发生语法错误。

但以下代码无例外地工作

OdbcCommand oc = Connection.CreateCommand();
oc.CommandText = String.Format("SELECT COUNT(*) AS CNT, MAX(someattr) AS attr1 FROM {0}", table.Name);
try
{
    OdbcDataReader or = oc.ExecuteReader();
    ...

参数化查询可能存在什么问题? :/

0 个答案:

没有答案