我想完成类似的事情:
try
{
openConnection();
OracleCommand cmd = new OracleCommand("SELECT CUSTOMER_ID, IMAGE_BLOB FROM CUSTOMER_IMAGE WHERE CUSTOMER_ID IN (3026)", conn);
string pubID = "";
OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
//create the report object
MemoryStream memStream;
DataSet ds = new DataSet();
DataTable ImageTable = new DataTable();
BinaryReader binReader;
DataRow dr;
byte[] byteArrName;
OracleLob blob;
while (reader.Read())
{
pubID = reader.GetValue(0).ToString();
// Obtain a LOB
blob = reader.GetOracleLob(1);
// Create a byte array of the size of the Blob obtained
byteArrName = new byte[blob.Length];
// Read blob data into byte array
int i = blob.Read(byteArrName, 0, System.Convert.ToInt32(blob.Length));
//Copied the contents of byte array to stream
memStream = new MemoryStream(byteArrName);
//Create a column of type byte[]
ImageTable.Columns.Add(new DataColumn("id", typeof(string)));
ImageTable.Columns.Add(new DataColumn("image", typeof(System.Byte[])));
//Reading the stream which has the blob data
binReader = new BinaryReader(memStream);
dr = ImageTable.NewRow();
dr["id"] = pubID;
//ReadBytes method to add a byte array of the image stream.
dr["image"] = binReader.ReadBytes((int)binReader.BaseStream.Length);
ImageTable.Rows.Add(dr);
memStream.Close();
binReader.Close();
}
ds.Tables.Add(ImageTable);
//Creating a temporary dataset which hold the image
ds.WriteXmlSchema(@Directory.GetCurrentDirectory() + "\\temp.xsd");
reader.Close();
conn.Close();
}
现在,我将在 Crystal Report 中填充 temp.xsd,以便动态显示图像。这只是我从头开始编写的示例代码,但为了适应我的场景,我需要获取已经存在的图像,dtAcctSigner.Rows[0]["IMAGE_BLOB"],
所以我想知道是否有任何方法可以获取这个 BLOB,就像我在上面的代码中获取一样
OracleDataReader.GetOracleLob();
为此,我需要将数据表(Type-OracleLob)的一列作为参数传递给这样的函数:
Update(dtAcctSigner.Rows[0]["IMAGE_BLOB"]);
功能如下:
public void Update(OracleLob a)
{
// I want to do take the OracleLob and make into a memorystream and put it into temp.xsd here
}
但我收到一个错误:
cannot convert 'object' to 'OracleLob'
请让我知道我做错了什么。