|
-
Jul 18th, 2008, 05:30 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2005] Load Image From SQL Server to Image Control
Hey I am havin some trouble loading an image from my sql db into a image on my form....
Using this code I got from the codebank:
vb Code:
Dim connection As New SqlConnection("blahblah")
Dim command As New SqlCommand("SELECT ImageData FROM Style_Images WHERE ImageID = 1", connection)
connection.Open()
Dim pictureData As Byte() = DirectCast(command.ExecuteScalar(), Byte())
connection.Close()
Dim picture As Image = Nothing
Using stream As New IO.MemoryStream(pictureData)
picture = Image.FromStream(stream)
End Using
When I try to assign picture to my Image control I get this message in the error list:
Value of type 'System.Drawing.Image' cannot be converted to 'System.Web.UI.WebControls.Image'
Am I completely off on the way to to do this?
-
Jul 18th, 2008, 05:35 PM
#2
Re: [2005] Load Image From SQL Server to Image Control
may be you can try this with namespace
Code:
Dim picture As System.Drawing.Image = Nothing
Dim stream As New IO.MemoryStream(pictureData)
picture = System.Drawing.Image.FromStream(stream)
__________________
Rate the posts that helped you 
-
Jul 18th, 2008, 05:40 PM
#3
Thread Starter
Frenzied Member
Re: [2005] Load Image From SQL Server to Image Control
yeah already importing System.Drawing
-
Jul 18th, 2008, 05:41 PM
#4
Re: [2005] Load Image From SQL Server to Image Control
but did you tried with above code (with fully qualified name)?
__________________
Rate the posts that helped you 
-
Jul 18th, 2008, 05:44 PM
#5
Thread Starter
Frenzied Member
Re: [2005] Load Image From SQL Server to Image Control
I think I described the problem wrong... basically confused on how to view the picture on the webform.
When I do
imgThumb = picture
I get the above error.
-
Jul 18th, 2008, 05:47 PM
#6
Re: [2005] Load Image From SQL Server to Image Control
can you show how imgThumb is declared?
__________________
Rate the posts that helped you 
-
Jul 18th, 2008, 05:48 PM
#7
Thread Starter
Frenzied Member
Re: [2005] Load Image From SQL Server to Image Control
<asp:Image ID="imgThumb" runat="server" Height="168px" Width="144px" />
-
Jul 18th, 2008, 06:25 PM
#8
Re: [2005] Load Image From SQL Server to Image Control
not sure if you would prefer saving image to disk and bind it to imgThumb??
Code:
Dim fs As New IO.FileStream(Server.MapPath("images\pic.jpeg"), FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(pictureData )
bw.Close()
imgThumb.ImageUrl = "images\pic.jpeg"
__________________
Rate the posts that helped you 
-
Jul 18th, 2008, 06:29 PM
#9
Thread Starter
Frenzied Member
Re: [2005] Load Image From SQL Server to Image Control
Yeah I already have them on disk if I wanted to go that way... but figured I would try to consolidate them into a table and work with them from there... If it can't be done through a table I will go back to using the .jpg's directly.
-
Jul 18th, 2008, 06:30 PM
#10
Re: [2005] Load Image From SQL Server to Image Control
well in above code i am still using jpg file your getting from SQL in form of byte in pictureData
__________________
Rate the posts that helped you 
-
Jul 18th, 2008, 06:34 PM
#11
Thread Starter
Frenzied Member
Re: [2005] Load Image From SQL Server to Image Control
getting FileMode is not declared. am I missing a namespace?
-
Jul 18th, 2008, 06:35 PM
#12
Re: [2005] Load Image From SQL Server to Image Control
it should be IO.FileMode.CreateNew
__________________
Rate the posts that helped you 
-
Jul 18th, 2008, 06:37 PM
#13
Thread Starter
Frenzied Member
Re: [2005] Load Image From SQL Server to Image Control
Cool that works... thanks alot dude...
You must spread some Reputation around before giving it to riteshjain1982 again.
-
Jul 18th, 2008, 06:38 PM
#14
Re: [RESOLVED] [2005] Load Image From SQL Server to Image Control
Glad it worked 
buddy you need to rate atleast 10 people before you can rate me
__________________
Rate the posts that helped you 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|