Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Viewing a SQL image type

Status
Not open for further replies.

tassflint

Programmer
Dec 29, 2005
21
US
Hello all,

I am receiving an error when I try to view an image that I have stored in my SQL database. I have used the following code :

Code:
cmd.Connection = conn
        cmd.CommandText = "Select filetype, img from ScanInfo"
        
        Try
            conn.Open()
            read = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
            Do While read.Read()
                Response.ContentType = read.Item("filetype")
                Response.BinaryWrite(read.Item("img"))
            Loop
            'stream.Write(pic, 0, pic.Length)
            'spic = New System.Drawing.Bitmap(stream)
            'Response.ContentType = "image/jpg"
            'spic.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
        Catch ex As Exception
            txtTester.Text = ex.ToString
        Finally
            conn.Close()
            stream.Close()
        End Try

When the page finally opens it tells me :

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

An invalid character was found in text content. Error processing resource


I am not sure how to get this resolved. The section of my code that is commented out does not work at all, which is why I switched to the other way.

Thanks in advance,

Brian
 
Hello all,

I figured out what was going wrong with my previous code. I had the wrong content type going in because the picture I choose was not of the same type as I had said it was.

Now I am having a different problem. The binarywriter does not produce the image, it just writes out the binary coding for the image. So I created a new page that has an image control in it and set the imageurl to the page with the binarywriter on it. The image still does not show up, does anyone have any ideas on why this is not working?



Thanks in advance,

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top