Vb.net 如何从.net中的am Informix查询中获取IfxBlob?
我似乎找不到一种方法只获取.Net下某个列的定位器对象。Informix似乎正在自动将blob列转换为Byte[],而没有留下改变这种行为的方法Vb.net 如何从.net中的am Informix查询中获取IfxBlob?,vb.net,informix,Vb.net,Informix,我似乎找不到一种方法只获取.Net下某个列的定位器对象。Informix似乎正在自动将blob列转换为Byte[],而没有留下改变这种行为的方法 IBM.Data.Informix.IfxConnection c = new IBM.Data.Informix.IfxConnection("..."); c.Open(); IBM.Data.Informix.IfxCommand cmd = new IBM.Data.Informix.IfxCom
IBM.Data.Informix.IfxConnection c =
new IBM.Data.Informix.IfxConnection("...");
c.Open();
IBM.Data.Informix.IfxCommand cmd =
new IBM.Data.Informix.IfxCommand("SELECT id,data FROM aaa", c);
IBM.Data.Informix.IfxDataReader r = cmd.ExecuteReader();
while (r.Read()) {
Debug.WriteLine(r.GetValue(1).GetType());
}
c.Close();
结果:
System.Byte[]
System.Byte[]
System.DBNull
System.DBNull
我期望:
IBM.Data.Informix.IfxBlob
或者类似的事情。我问了一位同事这件事,这是他对我的回答。因为这不是我的手艺,所以我的答案是“社区维基”,所以我没有得到荣誉(除了知道去哪里问)
要回答这个问题。。。以下程序是使用通用Informix提供程序(使用DRDA通信协议的IBM.Data.Informix.dll)编写的……您可以在“IBM Data Server Driver for CLI、ODBC和.NET”包中获得它。对于遗留的Informix提供程序(使用SQLI通信协议的IBM.Data.Informix.dll…您可以在“Informix客户端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)
方法请求返回。我问了一位同事,这是他的回答。因为这不是我的手艺,所以我的答案是“社区维基”,所以我没有得到荣誉(除了知道去哪里问)
要回答这个问题。。。以下程序是使用通用Informix提供程序(使用DRDA通信协议的IBM.Data.Informix.dll)编写的……您可以在“IBM Data Server Driver for CLI、ODBC和.NET”包中获得它。对于遗留的Informix提供程序(使用SQLI通信协议的IBM.Data.Informix.dll…您可以在“Informix客户端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)
方法,请求返回该列值。数据库表中的列的类型是什么?如果是BYTE或BLOB,那么为什么需要发明IBM.Data.Informix.IfxBlob类型呢?(可能有很好的理由;我不是任何人想象中的.NET专家。)类型是“创建表aaa(id序列,数据块)将数据放在“sbspace”中。IfxBlob是.Net驱动程序中的一种类型。我想做的是知道是否有blob,但按需获取。有效地延迟加载数据。更改架构是不可能的,因为它是一个非常大的遗留系统。数据库表中的列的类型是什么?如果是BYTE或blob,那么为什么会有blobe需要发明一种IBM.Data.Informix.IfxBlob类型(可能有很好的理由;我不是任何人想象中的.NET专家。)该类型是“创建表aaa(id序列,数据blob)将数据放入“sbspace”。IfxBlob是.Net驱动程序中的一种类型。我想做的是知道是否有斑点,但按需获取。有效地延迟加载数据。更改模式是不可能的,因为它是一个非常大的遗留系统。