我在读取数据库里的图片出现标题的错误,代码如下,找了半天,没找出原因。
 private void dataGridViewX3_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                if (dataGridViewX3.Rows.Count != 0)
                {
                    
                     WorkerId.Text =Convert.ToString(this.dataGridViewX3.CurrentRow.Cells[0].Value);
                     WorkerName.Text =Convert.ToString(this.dataGridViewX3.CurrentRow.Cells[1].Value);
                     WorkerSex.Text =Convert.ToString( this.dataGridViewX3.CurrentRow.Cells[2].Value);
                     WorkerAge.Text = Convert.ToString(this.dataGridViewX3.CurrentRow.Cells[3].Value);
                     WorkerCardId.Text =Convert.ToString( this.dataGridViewX3.CurrentRow.Cells[4].Value);
                     WorkerPost.Text = Convert.ToString(this.dataGridViewX3.CurrentRow.Cells[5].Value);
                     //Picture Deal
                                             byte[] GetImage = (byte[])dataGridViewX3.CurrentRow.Cells[6].Value;
                        Stream ImageStream = new MemoryStream(GetImage);
                        WorkerPic.Image = System.Drawing.Image.FromStream(ImageStream);
                        ImageStream.Close();
                   
                    WriteDate.Text = this.dataGridViewX3.CurrentRow.Cells[7].Value.ToString();                }
                else
                { 
                
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

解决方案 »

  1.   

    错误信息都不给。。两种原因:
    1)你存入的Image到byte可能有问题。希望能用其他方式验证数据是正确的。
    2)你的流可能是正确的,但是.net仅支持几种常用的图像格式.jpg,png等等,你的图像格式检查一下
    3)也是最有可能的,你代码的问题。你跟一下,看看Image到底有没有值。说实话,就你给出的这点错误信息,很不想回答你。
      

  2.   


    1.Image到byte
    2.ImageStream 都没有做判断
      

  3.   

    这个情况我以前碰到过,基本上都是文件夹权限不够造成的。
    你可以试试给文件夹“everyone”的完全控制权限