写入的时候可以关闭后赋值的
比如用打开文件对话框选择一个图像文件后保存到数据库DataRowCollection rc; 
DataRow myNewRow;object[] rowVals = new object[10];
rc = DS.Tables[0].Rows;
rowVals[0] = EmployeeID.Text;
......//给rowVals[i]赋值
rowVals[8] = sittinglocation.Text;FileStream st = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
BinaryReader mbr = new BinaryReader(st);
Byte[] buffer= new byte[st.Length];
mbr.Read(buffer, 0, (int)(st.Length));
st.Close();
//这时buffer已经有值,所以st可以关闭
rowVals[9] = buffer;myNewRow = rc.Add(rowVals);
读出时需要赋值后关闭
比如从数据库读出一条数据显示在pictureBox控件上byte[] p_stream = (byte[])dv_employee.Table.Rows[CurrentRow][9];
Stream st = new MemoryStream(p_stream);
picture.Image=Image.FromStream(st);
st.Close();

解决方案 »

  1.   

    using(MemoryStream ms = new MemoryStream(picData)){
      img = Image.FromStream(ms);
      myPictureBox.Image = img;  // 出错
      img.Save(@"D:\test.jpg",ImageFormat.JPEG);  // 出错
      ms.Close();
    }
      

  2.   

    对IMAGE的赋值和对它的使用一定都要在一起吗?
    我可能读入数据是在某一个时候
    而使用它又是一个时候
      

  3.   

    从指定的数据流创建 Image 对象。
    [C#]
    public static Image FromStream(
       Stream stream
    );参数
    stream 
    一个 Stream 对象,它包含此 Image 对象的数据。 
    返回值
    此方法创建的 Image 对象。备注
    在 Image 对象的生存期内,必须使流保持为打开。
    -------------------------------------------
    备注
    在 Image 对象的生存期内,必须使流保持为打开。
    -------------------------------------------
      

  4.   

    使用FolderBrowserDialog,.net Framework1.1中新增的类: 按钮处理函数用来打开一个路径选择框,private void buttonFolder_Click(object sender, System.EventArgs e){     FolderBrowserDialog myDialog = new  FolderBrowserDialog();     myDialog.ShowNewFolderButton = false;     myDialog.Description = "选择需要处理的解决方案或项目目录";     if(myDialog.ShowDialog()==DialogResult.OK)         this.textBoxFolder.Text = myDialog.SelectedPath;     myDialog.Dispose();}
    具体使用可以看这篇文章
    http://dev.csdn.net/develop/article/29/29248.shtm