fluminis  | Bonjour à tous
   Voila je tente en C# avec ODBC de recupérer une image stockée dans ma base de donnée dans un champ BLOB (en binaire donc) et de l'afficher directement dans une pictureBox.
   J'ai fait ça :
  
  Code :
 - public MemoryStream GetImage()
 - {
 - 	try
 - 	{
 -   int buffSize = 100;
 -   //Retrieve BLOB from database into DataSet.
 -   OdbcCommand commande = new OdbcCommand("SELECT image FROM telepilotes_tbl WHERE id_telepilote=9", myConnexion_);
 -   //Exécution de la requete
 -   OdbcDataReader resultat=commande.ExecuteReader();
 -   // On teste s'il existe au moins un résultat
 -   if (resultat.Read())
 -   {
 -   	int startIndex = 0;
 -   	// Read the bytes into outbyte[] and retain the number of bytes returned.
 -   	MemoryStream stmBLOBData = new MemoryStream();
 -   	byte[] outbyte = new byte[buffSize]; 
 -   	long retval = resultat.GetBytes(0, startIndex, outbyte, 0, buffSize);
 -   	// Continue reading and writing while there are bytes beyond the size of the buffer.
 -   	while (retval == buffSize)
 -   	{
 -     stmBLOBData.Write(outbyte,startIndex,buffSize);
 -     stmBLOBData.Flush();
 -     // Reposition the start index to the end of the last buffer and fill the buffer.
 -     startIndex += buffSize;
 -     retval = resultat.GetBytes(0, startIndex, outbyte, 0, buffSize);
 -   	}
 -   	stmBLOBData.Write(outbyte, 0, (int)retval - 1);
 -   	stmBLOBData.Flush();
 -   	return stmBLOBData;
 -   }
 - 	}
 - 	catch(Exception ex)
 - 	{
 -   MessageBox.Show(ex.Message);
 - 	}
 - 	MessageBox.Show("NuLLLLLL !" );
 - 	return null;
 - }
 
  |  
 
   pour ensuite l'utiliser comme ça :
 pictureBox1.Image = Image.FromStream(GetImage());
   mais ça ne fonctionne pas.
 J'ai une erreur "Offset et length hors limite pour ce tableau ou bien le nombre d'élément est supérieur au nombre d'éléments de l'index à la fin de la collection source"
          z'auriez une idée d'ou vient le pb ?
   merci d'avance
   fluminis    |