C# .NET - Error - Asked By ALOK RANJAN on 23-Apr-12 03:15 AM

hi everyone.

when we read image from datagrid

pictureBox1.Image =Image.FromFile(dgv_Driver.Rows[i].Cells[11].Value.ToString()); The name 'Image' does not exist in the current context


follwing error occured :

http://stackoverflow.com/questions/3445219/cannot-evaluate-expression-because-the-code-of-the-current-method-is-optimized



Somesh Yadav replied to ALOK RANJAN on 23-Apr-12 03:33 AM

It sounds like you are debugging an optimised / release build, despite having the optimised box un-checked. Things you can try are:

  • Do a complete rebuild of your solution file (right click on the solution and select Rebuild all)
  • While debugging open up the modules window (Debug -> Windows -> Modules) and find your assembly in the list of loaded modules. Check that the Path listed against your loaded assembly is what you expect it to be, and that the modified timestamp of the file indicates that the assembly was actually rebuilt.
  • The modules window should also tell you whether or not the loaded module is optimised or not - make sure that the modules window indicates that it is not optimised.

If you cant't see the Modules menu item in the Debug -> Windows menu then you may need to add it in the "Customise..." menu.

dipa ahuja replied to ALOK RANJAN on 23-Apr-12 03:36 AM
private void button1_Click(object sender, EventArgs e)
{
  SqlConnection conn = new SqlConnection(Program.c);
 
  SqlDataAdapter da = new SqlDataAdapter("Select images from pictures", conn);
 
  DataTable dt = new DataTable();
  da.Fill(dt);
 
  conn.Open();
  //display 1st image
  if (dt.Rows.Count > 0)
  {
    byte[] storedImage = (byte[])dt.Rows[3]["images"];
    Image newImage;
 
    MemoryStream stream = new MemoryStream(storedImage);
    newImage = Image.FromStream(stream);
 
    pictureBox1.Image = newImage;
 
    dataGridView1.Rows[0].Cells[0].Value = newImage;   
  }
}