Solved

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

Posted on 2011-09-13
3
268 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now