0

Hello All,

I have stored a Image in my sql server database and when i am tring to retrive the data the following error is coming..
(Conversion from string " 8901.jpg " to type 'Boolean' is not valid.)
In the database and also in the \\Debug\member file that .jpeg files are showing.. still i am getting the error.

I saw all the threads regarding Image retriving but it could not help me..

table name = employeeDtls
Field -- A_IMG nvarchar(10)

My code Is..

Public Sub ASSING(ByVal k As String)
str = Application.StartupPath & "\members\"
conn = GetConnect()
conn.Open()
Dim cmd As New SqlCommand("select * from EmployeeDtls where StaffNo='" & k & "'", conn)
Dim dr As SqlDataReader
dr = cmd.ExecuteReader

If dr.Read Then

If IsDBNull(dr.Item("A_IMG")) Then
Picimage.Image = Nothing
Else
k = dr.Item("A_IMG")
Picimage.Image = Image.FromFile(str, k)
End If
End If
conn.Close()

4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by nick.crane
0

Image.FromFile(str, k) is in error.
FromFile only takes one parameter for the filename.
The second parameter is a boolean for useEmbeddedColorManagement.
Try Image.FromFile(System.IO.Path.Combine(str, k))

0

Thanks Nick for your suggestion , ihave tried but one error is coming

(FileNotFoundException was Unhandeled by User Code)

Can u please help me on this ..Or if u have any example regarding "image saving and retriving "then please send the example" or shall i send my code then u can able to identify where the problem is..

I was tring this from last 3/4 days but i dont know in a pirticular point (From File)it is showing error..

Please help me..

0

FileNotFoundException says everything
do:
Debug.Writeline(System.IO.Path.Combine(str, k)) and check what the path is and compare it to the one you expected. im sure they are different

-1

The image is most likely stored as a byte stream in the database.
You have to read the image from the database into a byte array.
From there, you can read the byte array into a memory stream, which in turn is used to call: Image.FromStream(.....)

Votes + Comments
If you check the code this is clearly not the case!
0

The image is most likely stored as a byte stream in the database.
You have to read the image from the database into a byte array.
From there, you can read the byte array into a memory stream, which in turn is used to call: Image.FromStream(.....)

If you look at the code the file is clearly on disk and the DB contains the filename Field -- A_IMG nvarchar(10) .
The problem, as GeekByChoiCe said, is with getting the correct path and filename!

0

Thank You all..

Yes problem was in the path only...

Problem SOlved..........THANK YOU

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.