绑定图片pictureEdit1

 //绑定图片pictureEdit1
                if (floorNo != "")
                {
                    int Pictured = gridView1.FocusedRowHandle;
                    DataSet ds = initroom.SearchRoomInfo(fshopid);
                    string HasPicture = ds.Tables[0].Rows[Pictured]["HasPicture"].ToString();
                    if (HasPicture == "True")
                    {
                        Byte[] byteBLOBData = new Byte[0];
                        byteBLOBData = (Byte[])(ds.Tables[0].Rows[Pictured]["Pictured"]);
                        MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
                        pictureEdit1.Image = Image.FromStream(stmBLOBData);
                    }
                    else
                    {
                        pictureEdit1.Image = null;
                    }
                }

 2、在数据库中插入图片

 OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "图片类形(*.jpg;*.png;*.gif)|*.jpg;*.png;*.gif";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                pictureEdit1.Image = Image.FromFile(ofd.FileName);
                Byte[] byteBLOBData = new Byte[0];
                
                MemoryStream stmBLOBData = new MemoryStream();
                pictureEdit1.Image.Save(stmBLOBData, ImageFormat.Jpeg);
                Byte[] bytBLOBData = new Byte[stmBLOBData.Length];
                stmBLOBData.Position = 0;
                stmBLOBData.Read(bytBLOBData, 0, Convert.ToInt32(stmBLOBData.Length));
                SqlParameter prm = new SqlParameter("@BLOBData", SqlDbType.VarBinary, bytBLOBData.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bytBLOBData);


                EatGood.BLL.RoomManage.RoomManage.AlterRoom ar = new BLL.RoomManage.RoomManage.AlterRoom();
                string RoomNo = txt_RoomNo.Text.Trim();
                bool b = ar.UpdatePicture(bytBLOBData, RoomNo, fshopid);
                if (!b)
                {
                    MessageBox.Show("插入图片失败");
                }
                else
                {
                    InitRoomInfoGrid();
                }

 

posted @ 2012-12-03 16:30  qin孑  阅读(465)  评论(0编辑  收藏  举报