Click here to Skip to main content
15,912,021 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
pictureBox1.Image = Image.FromFile(dataGridView1.SelectedRows[0].Cells["dgimg"].Value.ToString());



Note: Am going to get the grid-view data into picture box while fetching the data am facing system.Byte[] issue

What I have tried:

<pre>pictureBox1.Image = Image.FromFile(dataGridView1.SelectedRows[0].Cells["dgimg"].Value.ToString());



Note: Am going to get the grid-view data into picture box while fetching the data am facing system.Byte[] issue
Posted
Updated 20-Apr-20 21:44pm

I think you need at least 2 things

1) a try/catch exception handler around your file code

2) debug print the contents of the cell dataGridView1.SelectedRows[0].Cells["dgimg"].Value.ToString() and ensure the value represents a full & correct path to the file, not just a relative path .. btw, if you implemented item (1) and logged the exception, it would probably show the existing file path and from that you may get the issue
 
Share this answer
 
v3
Look at the error message:
File not found exception was unhandled
It's couldn;t be any clearer if it tried: the file you told it to load the image from does not exist.

We can't help you with that: we don't have any access to your file system, or any idea what path you are feeding to the method - and you need both to try and work out what the problem might be.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
Garth J Lancaster 21-Apr-20 3:07am    
by heck it's hard to beat you to it !
OriginalGriff 21-Apr-20 3:18am    
I type fast.
And occasionally even accurately! :laugh:
Member 11297177 21-Apr-20 3:22am    
i have table employee am going to save the details of employee with employee photo and over there am take datatype image for photo.

after saving my details in DB image saved as system.byte[] so when am trying to update t
Member 11297177 21-Apr-20 3:23am    
while updating data am facing this challenge
Member 11297177 21-Apr-20 3:24am    
this is the code am convert into binary
byte[] ConvertImageToBinary(Image img)
{
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.ToArray();
}
}
Quote:
File not found exception was unhandled (system.byte[])

Which word you don't understand in "File not found" ?
You need to get the file name and check it:
C#
ImageFileName = dataGridView1.SelectedRows[0].Cells["dgimg"].Value.ToString();

By using an intermediate variable, you are able to print the file name you are looking for.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900