我问了一位同事,这是他对我的回应。由于这不是我的杰作,所以我给出了“社区维基”的答案,所以我没有得到赞誉(除了知道在哪里提问)。
要回答这个问题...以下程序是使用 Common Informix Provider(使用 DRDA 通信协议的 IBM.Data.Informix.dll 编写的...您可以在“IBM Data Server Driver for CLI, ODBC , 和 .NET" 包)。应该能够使用 Legacy Informix Provider(使用 SQLI 通信协议的 IBM.Data.Informix.dll ......您可以在“Informix Client SDK”包中获得它)来完成非常相似的事情。
这是一个示例程序:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using IBM.Data.Informix;
namespace InformixClob
{
class Program
{
static void Main(string[] args)
{
try
{
IfxConnection tConn = new IfxConnection("database=idsdb;server=my-system:9089;uid=informix;pwd=********");
tConn.Open();
IfxCommand tCmd = tConn.CreateCommand();
// create table mytesttab (col1 integer, col2 clob)
tCmd.CommandText = "select * from mytesttab";
IfxDataReader tRdr = tCmd.ExecuteReader();
while (tRdr.Read())
{
Console.WriteLine("Col1 is a {0}", tRdr.GetValue(0).GetType());
Console.WriteLine("Col2(GetValue) is a {0}", tRdr.GetValue(1).GetType());
Console.WriteLine("Col2(GetIfxValue) is a {0}", tRdr.GetIfxValue(1).GetType());
Console.WriteLine("Col2(GetIfxClob) is a {0}", tRdr.GetIfxClob(1).GetType());
}
tRdr.Close();
tConn.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
finally
{
Console.Write("Press ENTER"); Console.ReadLine();
}
}
}
}
这是它生成的输出:
Col1 is a System.Int32
Col2(GetValue) is a System.String
Col2(GetIfxValue) is a IBM.Data.Informix.IfxClob
Col2(GetIfxClob) is a IBM.Data.Informix.IfxClob
Press ENTER
该IfxDataReader.GetValue(int)
方法将以本机 .NET Framework 数据类型返回列值。要获取作为 Informix 类型返回的列值,您必须通过调用该GetIfxValue(int)
方法或者如果您可以更具体地通过该GetIfxClob(int)
方法请求它返回。