如何从数据库中选择图像并在图片框中显示? [英] How to select images from a database and show in a picture box?

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

问题描述

如何从数据库中选择图片并在图片框中显示?

i尝试linq to entity适用于所有类型的记录,但问题是如何从数据库表中选择图像?

i尝试



How to select pictures from a database and show in a picture box?
i tried linq to entity worked well for all types of records but problem is to how to select images from a database table?
i tried

using (dbe =new DatabaseEntities())
      {
          var images = from p in dbe.PitureTables
                       select p.Picture;
          foreach (var image in images)
          {
              MessageBox.Show("foreach Run");
              pictureBox2.Image = Image.FromStream(new MemoryStream(image.ToArray()));
          }
      }



没有任何错误,但foreach循环不会运行,在此代码块之前我插入了一个图像,如下所示


there is no any error but the foreach loop wont run, before this block of code i have inserted an image as following

using (dbe = new DatabaseEntities())
           {
              PitureTable record= new PitureTable {PictureName="pic1",Picture=imageToByteArray( pictureBox1.Image)};
                    dbe.StudentRecords.AddObject(record);
                    db.StudentRecords.Attach(record);
                    dbe.SaveChanges();
                    MessageBox.Show("inserted");
                }

推荐答案

通常我会以或多或少的细节回答大部分问题,所以很抱歉我在这种情况下不要这样做。原因是:这个问题很方便,而且CodeProject对它有很多答案,一次又一次地回答。请看这里:

http://www.codeproject.com/search.aspx?doctypeid=4%3b5&q=database+%28image+OR+picture%29+% 28store + OR + get + OR + retrieve%29 + PictureBox [ ^ ]。



如果从查询中删除 PictureBox ,你可以找到更多,因为它几乎无关紧要。



祝你好运,

-SA
Usually I answer most of questions in more or less fine detail, so I''m sorry that I don''t do it in this case. The reason is: this question is way, way too popular, and CodeProject keeps many answers to it, answered again and again. Please, just look here:
http://www.codeproject.com/search.aspx?doctypeid=4%3b5&q=database+%28image+OR+picture%29+%28store+OR+get+OR+retrieve%29+PictureBox[^].

You can find more if you remove PictureBox from the query, because it''s pretty much irrelevant.

Good luck,
—SA


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

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