1

同様のことを達成したい:

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'

私が間違っていることを教えてください。

4

1 に答える 1

0
using(reader)
{
      //Obtain the first row of data.
      reader.Read();
      //Obtain the LOBs (all 3 varieties).
      OracleLob BLOB = reader.GetOracleLob(1);
      ...

      //Example - Reading binary data (in chunks).
      byte[] buffer = new byte[4096];
      while((actual = BLOB.Read(buffer, 0, buffer.Length)) >0)
         Console.WriteLine(BLOB.LobType + 
            ".Read(" + buffer + ", " + buffer.Length + ") => " + actual);

      ...
}

私は個人的にこの方法でDataTableに列を作成して追加しますが、この方法で試すか、うまくいくことがわかっている別の方法で試すかはあなた次第です。

DataTable table = new DataTable("ImageTable"); //Create a new DataTable instance.

DataColumn column0 = new DataColumn("id"); //Create the column.
column.DataType = System.Type.GetType("System.String"); //Type string 

DataColumn column1 = new DataColumn("image"); //Create the column.
column.DataType = System.Type.GetType("System.Byte[]"); //Type byte[] to store image bytes.
column.AllowDBNull = true;
column.Caption = "My Image";

table.Columns.Add(column0); //Add the column to the table.
table.Columns.Add(column1); //Add the column to the table.

Then, add a new row to this table and set the value of the MyImage column.

DataRow row = table.NewRow();
row["MyImage"] = <Image byte array>;
tables.Rows.Add(row);
于 2012-08-27T22:05:46.507 に答える