C#如何在C#中将图像从数据库检索到图片框 [英] C# how to retrieve image from database into picturebox in c#

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

问题描述

SqlDataAdapter dataAdapter = new SqlDataAdapter(new SqlCommand("SELECT ImageName FROM Image WHERE Department='OSA REWORK'", con));
                    DataSet dataSet = new DataSet();
                    dataAdapter.Fill(dataSet, "Image");
 if (dataSet.Tables["Image"].Rows.Count > 0)
                    {

                        MemoryStream ms = new MemoryStream((byte[])dataSet.Tables["Image"].Rows[0]["ImageName"]);
                        ms.Position = 0;
                       
                 pictureBox1.Image = Image.FromStream(ms);//>error        
            }

推荐答案

这个无聊的问题经常被问到,以致再次回答是错误的.从寻找现有答案开始:
http://www.codeproject.com/search. aspx?doctypeid = 5& q =数据库+%28image + OR + images%29 + PictureBox [ http://www.codeproject.com/search.aspx? doctypeid = 5& q =数据库+%28image + OR + images%29 [
This rather boring question is asked so frequently that answering again would be wrong. Start with looking for existing answers:
http://www.codeproject.com/search.aspx?doctypeid=5&q=database+%28image+OR+images%29+PictureBox[^] (40 results),
http://www.codeproject.com/search.aspx?doctypeid=5&q=database+%28image+OR+images%29[^] (1326 results).

The number of found results shown at the moment of writing.



In your case, you need to debug your code to see what''s in the stream. For a test, you could simply copy your stream to a file stream to see if it''s a valid file or not. It could be incorrectly written in first place. It could be a file name instead of file content — many different problems are possible.

—SA


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

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