如何使用C#将来自MS SQL Server的图像显示到图片框中? [英] How to display image from ms sql server into picture box using c#?

查看:93
本文介绍了如何使用C#将来自MS SQL Server的图像显示到图片框中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码.但是我无法将图像显示在图片框中.我使用图像数据类型作为imageContent来存储图像.我能知道如何解决这个问题吗?


this is my code. But i cannot display the image into picture box. i use image data type as imageContent for store image. Can i know how to solve this problem??


SqlCommand sqlCmd = new SqlCommand("SELECT imageContent FROM printerBarCode pbc,PlantLayout pl WHERE pbc.Department=pl.Department,pbc.Location=pl.Location", con);
                        SqlDataAdapter SDA1 = new SqlDataAdapter(sqlCmd);
                        DataSet ds = new DataSet();  
                        SDA1.Fill(ds, "PlantLayout");  
                        int c = ds.Tables["Plantlayout"].Rows.Count; 
                         {   //BLOB is read into Byte array, then used to construct MemoryStream,  
                             //then passed to PictureBox.  
                            
                            Byte[] byteBLOBData = new Byte[0];  
                           byteBLOBData = (Byte[])(ds.Tables["PlantLayout"].Rows[c - 1]["imageContent"]);
                          
                         MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);  
                           
                           pictureBox1.Image = Image.FromStream(stmBLOBData); 
                         }

推荐答案

查看此链接:
http://stackoverflow.com/questions/8084590/如何将图片从sql服务器加载到图片框 [
See this link:
http://stackoverflow.com/questions/8084590/how-to-load-image-from-sql-server-into-picture-box[^]


仍会弹出消息无效数据". ..
still pop up the message"Invalid data"...


尝试一下.


http://www.redmondpie.com/inserting -in-and-retrieving-image-from-sql-server-database-using-c/ [
Try This.


http://www.redmondpie.com/inserting-in-and-retrieving-image-from-sql-server-database-using-c/[^]








M USman
(Pakistan)


这篇关于如何使用C#将来自MS SQL Server的图像显示到图片框中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆