tdisher
asked on
Retrieve image from SQL Server using vb.net
I have tried probably 10 different ways to get my .net application to display the images that are stored on my SQL server as type "image". The latest attempt is from this web site. I used the vb code. The uploaded images save in the database and have the proper size, but when it comes time to retrieve them, I get back only the broken image symbol. Debugging does not show any errors. Can anyone figure out why this would be? (As an aside, I cannot for the life of me figure out why clicking the submit button causes the submission to happen twice!)
I have downloaded the source code (from the dotnetcurry skydrive) and it works when I put it in a simple website. However, I have tried to add it to an existing web project for debugging and failed so maybe you have a similar problem? In that case some more info might be needed to find out what the actual problem is. When I tested it, I made some mistakes with database permissions but since you are seeing the records in the database I guess you've passed that station.
The 'aside' problem you mention (duplicate submit) is also mentioned in the comments on the page: it's ok in the download but from the aspx code posted on the page you have to remove
I did also see mention of this double submit causing empty image records so it could actually solve your problem?!
If not, can you retrieve an image directly? Try something like ...//your_website_and_path /ShowImage .ashx?id=1
The 'aside' problem you mention (duplicate submit) is also mentioned in the comments on the page: it's ok in the download but from the aspx code posted on the page you have to remove
onclick="btnSubmit_Click"
which is only needed in the C# version, the VB version has this code instead, defined after the Sub:Handles btnSubmit.Click
I did also see mention of this double submit causing empty image records so it could actually solve your problem?!
If not, can you retrieve an image directly? Try something like ...//your_website_and_path
ASKER
When I created a completely new web site, the dotnetcurry code worked perfectly. When I changed the sql to perform the lookup to my production database, it fails. I have to believe there is something wrong with the data being stored in my production database. Removing the onclick = did fix the duplicate record issue.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you just have to retrieve images from database through the reader. If you stored image height and width into database so it also you can retrieve with reader and you just write the following code
ltImage.Text = "<img src='../PathofImage/' & reader.item("ImageField")"