How to retrieve LONGBLOB image from mysql in picturebox
Hello,<br /> I need to retrieve the longblob of a picture from mysql.<br /><div> So first I insert it in the database with this:</div><div> <div class="dp-highlighter"><ol start="1" class="dp-c"><li class="alt"><span><span>MemoryStream ms = </span><span class="keyword">new</span><span> MemoryStream(); </span></span></li><li class=""><span> <span class="comment">// PIC_Image.Image.Save(ms, PIC_Image.Image.RawFormat);</span><span> </span></span></li><li class="alt"><span> <span class="keyword">byte</span><span>[] img = ms.ToArray(); </span></span></li><li class=""><span> </span></li><li class="alt"><span> <span class="keyword">string</span><span> q = </span><span class="string">"insert into tb_produits (Image) values('"</span><span> + img+ </span><span class="string">"')"</span><span>; <br /></span></span></li></ol></div></div><div>Here is to retrieve the picture : </div><div> <div class="dp-highlighter"><ol start="1" class="dp-c"><li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">static</span><span> Bitmap ByteToImage(</span><span class="keyword">byte</span><span>[] blob) </span></span></li><li class=""><span> { </span></li><li class="alt"><span> MemoryStream mStream = <span class="keyword">new</span><span> MemoryStream(); </span></span></li><li class=""><span> <span class="keyword">byte</span><span>[] pData = blob; </span></span></li><li class="alt"><span> mStream.Write(pData, 0, Convert.ToInt32(pData.Length)); </span></li><li class=""><span> Bitmap bm = <span class="keyword">new</span><span> Bitmap(mStream, </span><span class="keyword">false</span><span>); </span></span></li><li class="alt"><span> mStream.Dispose(); </span></li><li class=""><span> <span class="keyword">return</span><span> bm; </span></span></li><li class="alt"><span> </span></li><li class=""><span> } </span></li><li class="alt"><span> </span></li><li class=""><span> MySqlDataAdapter sda = <span class="keyword">new</span><span> MySqlDataAdapter(</span><span class="string">"SELECT * FROM tb_produits WHERE Designation='"</span><span> + Designation + </span><span class="string">"'and Reference='"</span><span> + Reference + </span><span class="string">"'"</span><span>, MyConnexion); </span></span></li><li class="alt"><span> DataTable dt = <span class="keyword">new</span><span> DataTable(); </span></span></li><li class=""><span> </span></li><li class="alt"><span> sda.Fill(dt); </span></li><li class=""><span> <span class="keyword">if</span><span> (dt.Rows.Count == 1) </span></span></li><li class="alt"><span> { </span></li><li class=""><span> <span class="keyword">byte</span><span>[] img = (</span><span class="keyword">byte</span><span>[])dt.Rows[0][</span><span class="string">"Image"</span><span>]; </span></span></li><li class="alt"><span> </span></li><li class=""><span> </span></li><li class="alt"><span> </span></li><li class=""><span> </span></li><li class="alt"><span> PIC_Image.Image = ByteToImage(img); </span></li><li class=""><span> } <br /></span></li></ol></div></div><div>I tried to retrieve but I got an error: <br /> Parameter is not valid in this line " Bitmap bm = new Bitmap(mStream, false);"</div><div> </div>