Click here to Skip to main content
15,566,625 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good afternoon,

how I can convert the image to bitmap. I store image inside my database and there is an error .

int index;
for (index = 1; index <= dt.Rows.Count; index++) {

bmDatabaseImage = (Bitmap)Image.FromFile(dt.Rows(index));
}

it shows the error under "Rows"
Posted
Comments
Herman<T>.Instance 2-Apr-13 6:29am    
which exception do you get?
hajis 2-Apr-13 6:34am    
nun-invocable member 'System.DataTable.Rows' cann not be used like amethod

Change the brackets:
C#
bmDatabaseImage = (Bitmap)Image.FromFile(dt.Rows(index));
Becomes
C#
bmDatabaseImage = (Bitmap)Image.FromFile(dt.Rows[index]);

But it may be worth your looking at this: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^]
 
Share this answer
 
Hi,

Try this:
C#
bmDatabaseImage = (Bitmap)Image.FromFile(dt.Rows[index]);
 
Share this answer
 
Comments
hajis 2-Apr-13 6:51am    
I try this but it doesn't work..

this error i get:


The best overloaded method match 'System.Drawing.Image.FromFile(string)' has some invalid arguments
Thomas Daniels 2-Apr-13 7:20am    
Because the Image.FromFile method needs a string as argument, and a row from a data table isn't a string.
hajis 2-Apr-13 7:25am    
so what i can do to solve this ?
can you show me an example?
Thomas Daniels 2-Apr-13 7:35am    
I'm sorry, I can't give an example, because I don't know the cells of the row. If you provide the cell number in which the file name is shown, I can give an example.
The error itself is cause you are misusing the Rows property[^]. It is a collection, thus an indexable object. Use square braces.
 
Share this answer
 
Comments
hajis 2-Apr-13 6:50am    
I try this but it doesn't work..

this error i get:


The best overloaded method match 'System.Drawing.Image.FromFile(string)' has some invalid arguments
Zoltán Zörgő 2-Apr-13 7:09am    
That's an other error :)
As I said, you made a syntax error before. But you will get some more if you follow this path. This is not the way to do it.
You should read the link given by OriginalGriff!

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