求教大家,C#窗体中如何上传图片,以及如何保存到数据库(sql),怎么可以可以解析出来现世到pictureBox中,谢谢诶大家,给小弟解决下,要详细点的,注释详细点,小弟初学者,,谢谢了,

解决方案 »

  1.   

    http://blog.csdn.net/LOVESONGFOREVER/archive/2010/11/26/6037031.aspx足以解决你的问题了。
      

  2.   

    http://blog.csdn.net/LOVESONGFOREVER/archive/2010/08/11/5803261.aspx
      

  3.   

    4楼以的可以解决问题,你需要把数据库的字段改成image类型的(2005后事varbinary类型了)。然后把byte数组赋值过去直接执行。
    插入数据库       
                 OpenFileDialog open = new OpenFileDialog();
                open.Filter = "*.jpg|*.jpg";
                byte[] photo_byte = null;
                if (open.ShowDialog() ==DialogResult.OK)
                {
                    using (FileStream fs = new FileStream(open.FileName, FileMode.Open, FileAccess.Read))
                    {
                        using (BinaryReader br = new BinaryReader(fs))
                        {
                            photo_byte = br.ReadBytes((int)fs.Length);
                        }
                    }
                }  //插入语句如insert into A(Image) values("'photo_byte'") 
    显示
    byte[] bytes=(byte[])reader["Image"];//Image为数据库中存放Image类型字段         using (MemoryStream ms = new MemoryStream(bytes))   
               {   
                   ms.Write(bytes, 0, bytes.Length);   
                   picturebox1.image= Image.FromStream(ms, true);   
              }   
     
      

  4.   

    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Filter = "イメージファイル(*.gif,*.jpg,*.jpeg,*.bmp,*.wmf,*.png)|*.gif;*.jpg;*.jpeg;*.bmp;*.wmf;*.png";
                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        FileInfo f = new FileInfo(ofd.FileName);
                            file = ofd.FileName;
                            this.pictureBox1.Image = Image.FromFile(file);
                    }
    可以定义Image 类型 ,数据库中也有这个类型,就像其他类型一样操作就行了
      private Image iMAGE;
            public Image IMAGE
            {
                get { return iMAGE; }
                set { iMAGE = value; }
            } obj.IMAGE = pictureBox1.Image;