C sharp - Problema Lectura Blob en Base de Datos!!!!

 
Vista:

Problema Lectura Blob en Base de Datos!!!!

Publicado por colosoderada (9 intervenciones) el 17/10/2005 13:21:49
Hola estoy intentado leer un campo de tipo "foto" BLOB de una base de datos en interbase 5.6 usando ODBC pero no hay manera.

He probado con estos dos tipos de código y siempre me dan problemas de conversión:

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

También he probado con este pero también me da error de conversión en la línea
Byte[(tOdbcDataReader_origen.GetBytes(PictureCol, 0, null, 0, int.MaxValue))];"

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

Alguna idea ???? Algún ejemplo ????
Mi correo [email protected]

Gracias por leer este mensaje y un saludo.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Problema Lectura Blob en Base de Datos!!!!

Publicado por Edgar (278 intervenciones) el 17/10/2005 14:34:43
Hola

A mi ma habia sucedido algo similar en una ocasion, lo que hice fue crear un procedimiento almacenado que me devolviera la imagen y cuando ejecutaba el método Fill lo hacia sobre un DataTable y no en un Dataset

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar