| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 877 人关注过本帖
标题:》》》》》PictureBox 与数据库问题~~~~~~~~~~~~~~~
只看楼主 加入收藏
lfxwl_love
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-9-12
收藏
 问题点数:0 回复次数:2 
》》》》》PictureBox 与数据库问题~~~~~~~~~~~~~~~
单击PICTUREBOX,把图片弄到这个空间里面去。
如何把picturebox里面的图片存入数据库。又如何从数据库中读取这个图片。
搜索更多相关主题的帖子: 数据库 PictureBox 
2008-09-23 09:54
小仙
Rank: 7Rank: 7Rank: 7
来 自:光之谷
等 级:贵宾
威 望:39
帖 子:1812
专家分:1
注 册:2008-8-8
收藏
得分:0 
我发过这个帖子,解决拉。查下~
2008-09-24 20:51
Mo诫
Rank: 4
等 级:业余侠客
帖 子:80
专家分:223
注 册:2009-7-29
收藏
得分:0 
                OpenFileDialog FDup = new OpenFileDialog ();
                FDup.Filter = "Image(*.jpg)|*.jpg|(*.bmp)|*.bmp|(*.png)|*.png";
                if (FDup.ShowDialog() == DialogResult.OK)
                {
                    FilePath = FDup.FileName;
                    this.txbPath.Text = FilePath;
                }

            //把图片转换为数据流
                        FileName = this.txbPath.Text;
                        FileStream Fstream = new FileStream(FileName, FileMode.Open, FileAccess.Read);
                        Byte[] mybtye = new Byte[Fstream.Length];
                        int bt = Fstream.Read(mybtye, 0, Convert.ToInt32(Fstream.Length));//必需的.把数据流转换为int
                        Fstream.Close();
 
                        F_str_str = "insert into Document_Image (Document_ID,Image) values('" + this.txbDocument_ID.Text.ToString().Trim() + "',@Image)";
                        SqlConnection sqlcon = basoprate.GetCon();
                        sqlcon.Open();
                        SqlCommand mycmd = new SqlCommand(F_str_str, sqlcon);
                        //设置变量@Image值
                        SqlParameter sqlptr = new SqlParameter("@Image", SqlDbType.Image);
                        sqlptr.Value = mybtye;
                        mycmd.Parameters.Add(sqlptr);
                        mycmd.ExecuteNonQuery();
************************************************************************************
            string F_str_str = "Select Image from Document_Image";
            byte[] mybyte = new byte[0];
            SqlDataReader myread = basOprt.GetRead(F_str_str);
            while (myread.Read())
            {
                mybyte = (byte[])myread["Image"];//转换为进制数
                MemoryStream Mstream = new MemoryStream(mybyte);//把数据转换为数据流
                Image img = Image.FromStream(Mstream, true);//把数据流转换为图片
                //设置图片显示格式
                Bitmap map = new Bitmap(img);
                Point pot = new Point(map.Size);
                if (pot.X > pictureBox.Width || pot.Y > pictureBox.Height)
                {
                    pictureBox.SizeMode = PictureBoxSizeMode.Zoom;
                }
                else
                {
                    pictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
                }
                pictureBox.Image = img;
            }
2009-09-29 13:06
快速回复:》》》》》PictureBox 与数据库问题~~~~~~~~~~~~~~~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042289 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved