{ byte[] bytes= (byte[])dataset.Tables[0].Rows[this.listBox1.SelectedIndex][1]; MemoryStream memStream=new MemoryStream(bytes); try { Bitmap myImage = new Bitmap(memStream); this.pictureBox1.Image= myImage; } catch { this.pictureBox1.Image=null; } } ⑹ 添加“更换图片”的Click事件代码 private void buttonUpdateImage_Click(object sender, System.EventArgs e) { OpenFileDialog openFileDialog1=new OpenFileDialog(); openFileDialog1.ShowDialog(); if (openFileDialog1.FileName.Trim()!="") { Stream myStream = openFileDialog1.OpenFile(); int length=(int)myStream.Length; byte[] bytes=new byte[length]; myStream.Read(bytes,0,length); myStream.Close(); dataset.Tables[0].Rows[this.listBox1.SelectedIndex][1] =bytes; ShowImage(); } } ⑺ 添加“移除图片”的Click事件代码 private void buttonMoveImage_Click(object sender, System.EventArgs e) { byte[] bytes= System.Text.Encoding.Unicode.GetBytes(""); dataset.Tables[0].Rows[this.listBox1.SelectedIndex][1]= bytes; |