2012-08-27 5 views
1

에 매개 변수로 OracleLob 전달 : 이제나는 비슷한 일을 수행하고자하는 기능

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(); 
} 

, 나는 이미지가 동적으로 표시됩니다 있도록 수정 보고서에서 그 temp.xsd를 채울 수 있습니다. 이것은 처음부터 쓴 예제 코드 일 뿐이지 만 시나리오를 적용하기 위해 이미 dtAcctSigner.Rows[0]["IMAGE_BLOB"],에있는 이미지를 가져와야하므로 위의 코드를

으로 가져 오는 것처럼이 BLOB를 가져올 수있는 방법이 있는지 궁금합니다. 이를 위해
OracleDataReader.GetOracleLob(); 

는,이 같은 함수에 매개 변수로 데이터 테이블 (유형-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' 

날 내가 잘못 뭘하는지 알려 주시기 바랍니다.

+0

일을 알고이 방법이나 다른 방법을 시도하는 당신에게 달려 것 그럼 .. 또한 비어있는 코드 메소드를 게시하지 마십시오 .. 우리가 당신을 도울 수 있다면, 당신은 당신이 가지고있는 문제에 관해 좀 더 명확하고 구체적이어야합니다. 이것은 약간 혼란 스럽습니다/어렵습니다. 당신이 성취하고자하는 것을 따라하십시오. 전달 방법에 대한 전체 코드를 보여주십시오. 업데이트 (dtAcctSigner.Rows [iCount1] [ "SIGNATURE_BLOB"]); 뿐만 아니라 데이터 테이블을 선언 할 때 – MethodMan

+0

감사합니다. 코드를 편집합니다. 일을 할 때 정말 1. 자연 3의 매우 추상적 인 개별 2로 충분한 연구를 표시하지 않는 question..etc –

+0

대부분의 사람들은 downvote : 나는 PLS, 질문을 편집 그것 좀 봐 – MethodMan

답변

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); 
+0

이 코드는 청크에 대해 알게 해줍니다. 하지만 런타임에 CrystalReports에서 이미지를 쓰기 가능하게해야하기 때문에이를 메모리 스트림으로 변환합니다. –

+0

오, 알았어. 나는 그걸 알지 못했다. 나는 DataTable을 만들고, 내가 위에있는 해답 아래의 열을 어떻게 할당하는지에 대한 또 다른 예제를 추가하려고한다. – MethodMan

+0

이것을 메모리 스트림으로 가져 와서 임시 XML 스키마를 하드 디스크에 저장하여 CrystalReports에 채울 수 있습니다. 또한, reader.GetOracleLob을 사용하기 위해 OracleDataReader를 사용하지 않고 Datatable에서이 BLOB 객체를 사용했습니다. 따라서 OracleDataReader없이 oraclelob로 데이터 테이블의 열을 변환 할 수있는 방법을 알아야합니다. –

관련 문제