Solved

How do I get an image from DB into an asp.net control?

Posted on 2011-09-13
3
274 Views
Last Modified: 2012-05-12
Below is my code that works the way it is written... it pulls the blob image out of the database and displays it on a webpage. But what if I want it to display in a control on that webpage? Right now I have 2 aspx pages.

The first one just gives the second on the ID.
<a href="WebForm1.aspx?ID=70">Go</a>


The second one displays the image. But I need to put other information on this page so I need the image to go into a placeholder. I just put an <img> tag on this page. How do I get the output from the below code to go into that img tag?

<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<% @Import Namespace="System.IO" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.SqlClient" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        WebForm1

    </div>
    <div>
        <script runat="server">
           
            Private Overloads Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

                Dim sSQL As String = "SELECT ThumbNailPhoto FROM Production.ProductPhoto WHERE ProductPhotoID='" & Request.QueryString("ID") & "'"
                Dim myReader2 As SqlDataReader
                Dim myConnection2 As SqlConnection = New SqlConnection
                myConnection2.ConnectionString = ConfigurationManager.ConnectionStrings("FT_Data").ConnectionString
                Dim myCommand2 As SqlCommand = New SqlCommand()
               
                With myCommand2
                    .CommandText = sSQL
                    .CommandType = CommandType.Text
                    .Connection = myConnection2
                    .Connection.Open()
                    myReader2 = .ExecuteReader(CommandBehavior.CloseConnection)
                End With

                While myReader2.Read
                    Response.BinaryWrite(myReader2("ThumbNailPhoto"))
                End While

                myCommand2.Dispose()
                myConnection2.Dispose()

            End Sub

        </script>

    <div style="background-color: #000000; border: medium solid #C0C0C0">
        <img alt="" id="myimage" name="myimage" src="" runat="server"/>
    </div>
       

    </div>
    </form>
</body>
</html>
0
Comment
Question by:md0333
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 36533771
Hello,

You have to put one literal control for getting image, and into coding side, you have to write like this.

Get the data into DataReader

While Reader.Read

literal1.Text = "<img src='../Images/' " & Reader.Item("ImageFiledName") & " height='' width='' />"

End While
0
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36533806
0
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 500 total points
ID: 36535666
Place asp:image control in your aspx page and call a HTTPHandler by passing id of the image as a paramerter. Implement database accessing business logic in  the HTTP handler.

http://stackoverflow.com/questions/46788/how-to-bind-a-memorystream-to-aspimage-control gives clear idea. Please go through it.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question