从SQL数据库中检索图像 [英] retriving image from sql database

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

问题描述

你好,
从数据库检索图像时收到诸如参数无效"之类的错误.
这是我的代码:-

Hello,
I have received errors such as "parameter not valid" while retrieving an image from a database.
Here is my code:-

string temp = "B0010C++0002D";
           SqlConnection CN = new SqlConnection(conn);

           //Initialize SQL adapter.
           SqlDataAdapter ADAP = new SqlDataAdapter("select photo from entry_master where item_id=''" + temp + "''and ayid=''AY0001'' and active = 0", CN);

           //Initialize Dataset.
           DataSet DS = new DataSet();

           //Fill dataset with ImagesStore table.
           ADAP.Fill(DS, "entry_master");

           //Fill Grid with dataset.
           //dataGridView1.DataSource = DS.Tables["ImagesStore"];

           byte[] imageData =(byte[])DS.Tables["entry_master"].Rows[0]["photo"];

           Image newImage;
           //Read image data into a memory stream
           using (MemoryStream ms = new MemoryStream(imageData, 0, imageData.Length))
           {
               ms.Write(imageData, 0, imageData.Length);

               //Set image variable value using memory stream.
               newImage = Image.FromStream(ms,true);//ERROR
           }

           //set picture
           picimg.Image = newImage;



请帮助



Please help

推荐答案

从SQL Server存储和检索图像使用Microsoft .NET [ ^ ] CP的文章可能会对您有所帮助.
Storing and Retrieving Images from SQL Server using Microsoft .NET[^]article from CP might help you.


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

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