Problem reading BLOB field fron DataBase !!!!!!

Oct 17 2005 6:46 AM

Hi, I´m trying to read from a DataBase "InterBase 5.6"  records with a field of type BLOB, using ODBC connection but it is impossible.

I have tried with this code: "but the image is not shown

    SqlConnection cn = new SqlConnection(strCn); cn.Open();

   //Retrieve BLOB from database into DataSet. SqlCommand

   cmd = new SqlCommand("SELECT BLOBID, BLOBData FROM BLOBTest ORDER BY BLOBID", cn);

   SqlDataAdapter da = new SqlDataAdapter(cmd);

   DataSet ds = new DataSet();

   da.Fill(ds, "BLOBTest");

   int c = ds.Tables["BLOBTest"].Rows.Count;

     if(c>0)

     { //BLOB is read into Byte array, then used to construct MemoryStream,

    //then saved to a file.

     Byte[] byteBLOBData = new Byte[0];

     byteBLOBData = (Byte[])(ds.Tables["BLOBTest"].Rows[c - 1]["BLOBData"]);

    MemoryStream stmBLOBData = new MemoryStream(byteBLOBData); Image image =               Image.FromStream(stmBLOBData); image.Save(@"c:\test.bmp");

     }

     cn.Close(); }

catch(Exception ex) {MessageBox.Show(ex.Message);}

I have tried with this code  bu i have got a error convertion in line "Byte[] b = new Byte[(tOdbcDataReader_origen.GetBytes(PictureCol, 0, null, 0, int.MaxValue))];"

This is the code:

int i = 0;

int bufferSize = 100;

byte[] outbyte = new byte[bufferSize];

int PictureCol = 1; // the column # of the BLOB field

OdbcConnection tConnection_origen = new OdbcConnection(tConnectionString_origen);
OdbcCommand tOdbcCommand_origen = new OdbcCommand(tSQLString_origen, Connection_origen);

tConnection_origen.Open();

OdbcDataReader tOdbcDataReader_origen = tOdbcCommand_origen.ExecuteReader(CommandBehavior.SequentialAccess);

Byte[] b = new Byte[(tOdbcDataReader_origen.GetBytes(PictureCol, 0, null, 0, int.MaxValue))];

tOdbcDataReader_origen.GetBytes(PictureCol, 0, b, 0, b.Length);

tOdbcCommand_destino.Parameters.Add( tOdbcDataReader_origen.GetName(i), tOdbcDataReader_origen.GetBytes(PictureCol, 0, b, 0, b.Length));

retval = tOdbcDataReader_origen.GetBytes(1, startIndex, outbyte, 0, bufferSize);

// Continue reading and writing while there are bytes beyond the size of the buffer.

while (retval == bufferSize){

stmBLOBData.Write(outbyte,startIndex,bufferSize);

stmBLOBData.Flush();

// Reposition the start index to the end of the last buffer and fill the buffer.

 startIndex += bufferSize;

 retval = tOdbcDataReader_origen.GetBytes(0, startIndex, outbyte, 0, bufferSize);

//}


Any idea ????? Any code that i can write ?????
Any example ????

Thanks in advance.