private void ReadPictureFromDB() { MriyaUserDataDataSet.UserPhotoDataTable tablePhoto = new MriyaUserDataDataSet.UserPhotoDataTable(); MriyaUserDataDataSetTableAdapters.UserPhotoTableAdapter tablePhotoAdapter = new MriyaUserDataDataSetTableAdapters.UserPhotoTableAdapter(); m_rowPicture = null; pictureBox1.Image = null; if (m_nRecordID < 1) { return; } tablePhoto.Clear(); try { tablePhotoAdapter.FillById(tablePhoto, m_nRecordID); } catch (Exception ex) { MessageBox.Show("Помилка завантаження фотографії:\r\n" + ex.Message, "Загрузка фото", MessageBoxButtons.OK, MessageBoxIcon.Warning); pictureBox1.Refresh(); return; } if (tablePhoto.Rows.Count > 0) { m_rowPicture = tablePhoto.Rows[0] as MriyaUserDataDataSet.UserPhotoRow; } if (m_rowPicture != null) { System.IO.MemoryStream streamMem = new System.IO.MemoryStream(m_rowPicture.PhotoBinary); pictureBox1.Image = System.Drawing.Image.FromStream(streamMem); } else { pictureBox1.Refresh(); } m_bUploadPending = false; buttonUpload.Enabled = false; buttonDelete.Enabled = (m_rowPicture != null); buttonSaveImageAs.Enabled = (m_rowPicture != null); }
private void ReadPictureFromDB() { MriyaUserDataDataSet.UserPhotoDataTable tablePhoto = new MriyaUserDataDataSet.UserPhotoDataTable(); MriyaUserDataDataSetTableAdapters.UserPhotoTableAdapter tablePhotoAdapter = new MriyaUserDataDataSetTableAdapters.UserPhotoTableAdapter(); m_rowPicture = null; pictureBox1.Image = null; if (m_nRecordID < 1) return; tablePhoto.Clear(); try { tablePhotoAdapter.FillById(tablePhoto, m_nRecordID); } catch(Exception ex) { MessageBox.Show("Помилка завантаження фотографії:\r\n" + ex.Message, "Загрузка фото", MessageBoxButtons.OK, MessageBoxIcon.Warning); pictureBox1.Refresh(); return; } if (tablePhoto.Rows.Count > 0) m_rowPicture = tablePhoto.Rows[0] as MriyaUserDataDataSet.UserPhotoRow; if (m_rowPicture != null) { System.IO.MemoryStream streamMem = new System.IO.MemoryStream(m_rowPicture.PhotoBinary); pictureBox1.Image = System.Drawing.Image.FromStream(streamMem); } else { pictureBox1.Refresh(); } m_bUploadPending = false; buttonUpload.Enabled = false; buttonDelete.Enabled = (m_rowPicture != null); buttonSaveImageAs.Enabled = (m_rowPicture != null); }