在C#中从SQL Server检索图像 [英] retrieve image from sql server in c#

查看:102
本文介绍了在C#中从SQL Server检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using (SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\meekun.poon\\My Documents\\Visual Studio 2008\\Projects\\TrackLocation\\TrackLocation\\barcodePrinter.mdf;Integrated Security=True;User Instance=True"))
                    {
                        conn.Open();
                        using (SqlCommand cmd = new SqlCommand("SELECT ImageName FROM Image WHERE ImageID='PL001'", conn))
                        {
                            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                            DataSet dataSet = new DataSet();
                            adpt.Fill(dataSet, "Image"); 
                            DataRow Row;
                            Row = dataSet.Tables["Image"].Rows[0];
                            byte[] MyImg = (byte[])Row[0];
                            MemoryStream ms = new MemoryStream(MyImg);
                            ms.Position = 0;
                                
                            Image img = Image.FromStream(ms); //error 
                            
                         pictureBox1.Image = img;
                            
                        }
                        conn.Close();
                    }


如何解决这个问题呢??? imagename是图像数据类型!错误消息->参数无效.紧急!!!感谢


how to solve this problem??? imagename is image data type!! error message->parameter is not valid. URGENT!!! thanks

推荐答案

看看这个:
> http://stackoverflow.com/questions/2175209/retrieve-images-from-sql-服务器数据库 [ ^ ]
还有这个:
使用Streded Procedures和C#.net从SQL Server存储和检索图像 [ ^ ]
Have a look at this:
http://stackoverflow.com/questions/2175209/retrieve-images-from-sql-server-database[^]
and this as well:
Storing and Retrieving Images from SQL Server Using Strored Procedures and C#.net[^]


这篇关于在C#中从SQL Server检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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