473,657 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting Images into a Repeater from SQL Server

I am developing an application that uses SQL 2000 as my source of
images. I have successfully created the code to load the images onto
the SQL Server and also to retrieve the images into a dataset. I
tested the application by populating a Dataset with the images from
SQL Server and rendered just one of the images by using a bitmap and
inserting the resulting stream into the response stream as a Jpeg
format.

My next move was to bind this returned set to an image control that I
included in a Repeater control. I set the datasource property in code
as follows:

ds = si.SqlBLOB2DS(" GdsTest", "Picture", "Category", "Test")
GdsPicsRepeater .DataSource = ds.Tables(0).De faultView
GdsPicsRepeater .DataBind()

The I included the follwing in the HTML view:

<asp:Repeater id="GdsPicsRepe ater" runat="server">
<ItemTemplate >
<table>
<tr>
<td>
<img src= <%#
DataBinder.Eval (Container,"Dat aItem.Picture") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
When the repeater is rendered it shows the correct number of images
from the dataset, but it doesn't show the actual image.
I am not using the response steam in this case.

Any help please?

Regards
John L
Nov 19 '05 #1
7 6313
You're almost there. Just a couple of things:

*Create a separate page that extracts the image from SQL Server and
saves it to a stream (just as you've already done!). Pass the image id
to this page in the querystring (i.e., generateimage.a spx?pictureid=2 7)
so that it knows which image to extract.

In your repeater, set the src for the image to the page above, passing
the image identifier as in

<img src=<%# "generateimage. aspx?pictureid= " &
DataBinder.Eval (Container.Data Item, "pictureid" )%>

Bill E.
Hollywood, FL

Nov 19 '05 #2
Thank you very much for your response. I can understand the need to
call on the aspx page to render the picture deltails. However, I'm
concerned about passing a specific ID for this picture. After all, the
repeater is going to want a different picture as it populates each
entry in the list so I need the repeater to generate a different value
each time.
Regards

John L

On 8 May 2005 07:11:37 -0700, bi********@nets cape.net wrote:
You're almost there. Just a couple of things:

*Create a separate page that extracts the image from SQL Server and
saves it to a stream (just as you've already done!). Pass the image id
to this page in the querystring (i.e., generateimage.a spx?pictureid=2 7)
so that it knows which image to extract.

In your repeater, set the src for the image to the page above, passing
the image identifier as in

<img src=<%# "generateimage. aspx?pictureid= " &
DataBinder.Eva l(Container.Dat aItem, "pictureid" )%>

Bill E.
Hollywood, FL


Nov 19 '05 #3
gemel,

You would be passing the id of each picture in your repeater. If, for
example, your repeater will show ten pictures, you will pass the id for
all ten to the page that generates the image. That page will be called
ten times--once for each image shown in the repeater.

Personally, I never store images in the database. I instead I place
the image itself on the file server and I store a string that
represents the path to the image file in the database. I modify the
path a bit to create the src for the img control. Therefore, there is
no need to call another page to generate a stream for each image.

Bill

Nov 19 '05 #4
Bill,
Thanks for your patience on this one. I agree that storing the
images directly on the server is easier than this approach. My problem
is that my ISP gives me storage on the web server and also on the SQL
server. If I use the SQL server for images then I don't have to use my
quota of space on the web server. I also wanted to get experience with
disconnected operation using datasets.

This has led me to the current problem. I'm not sure that I fuly
understand the repeater when it comes to this particular function. I
know you gave me a good example but this applied to just one image (I
think). My dataset contains only the list of images stored in a single
BLOB column, I didn't pouplate it with IDs of those BLOBs. I assumed I
would just be looking at the range of row numbers contained in the
dataset which is a contiguous range starting at 0.
I would therefore be grateful (but tedious) if you would give me an
example to use in these circumstances. Its the arguments that I send
to this page as part of the source address that is confusing me.

Regards

John L

On 8 May 2005 15:48:45 -0700, bi********@nets cape.net wrote:
gemel,

You would be passing the id of each picture in your repeater. If, for
example, your repeater will show ten pictures, you will pass the id for
all ten to the page that generates the image. That page will be called
ten times--once for each image shown in the repeater.

Personally, I never store images in the database. I instead I place
the image itself on the file server and I store a string that
represents the path to the image file in the database. I modify the
path a bit to create the src for the img control. Therefore, there is
no need to call another page to generate a stream for each image.

Bill


Nov 19 '05 #5
gemel,

The example I gave you applied to multiple images, not just one.
However, I suppose that I was not clear enough in my explanation so let
me try to clarify.

I assume that your SQL server database has a table that contains a list
of images, including a BLOB column to store the actual image. However
this table MUST also contain a way to identify each row in the table so
that you can retrieve a single image. If you don't have such a column,
you can add an identity column to the table so that it generates a
sequential identifier for each row. On the other hand, if you're
storing the name if each image in one of the columns and this name is
unique, you could also use the name to identify the image, but this
could present some problems if the names use strange characters. Let's
assume that you create an identity column called PictureID so that you
now have a unique identifier associated with each of your images.

You will need to create an image generator page which creates a
response stream for ONE IMAGE AT A TIME. Let's assume that you call it
"generateimage. aspx" This page would likely contain code that extracts
a single BLOB into a byte array then saves it to an output stream (I
assume that you already know how to do this because you seemed to
indicate that you do). The code in generageimage.a spx will take a
single PictureID passed to it in the query string and retrieve a single
image from the database using this PictureID by creating a
dataset/datatable with a single row, BLOB column included. The single
image in the BLOB column is retrieved into a byte array and then sent
to the output stream.

Lastly, you will have another page with a repeater used to view
multiple pictures. Let's call it "viewpictures.a spx". You will
populate the repeater with a dataset based on a query of the table with
the BLOB, but YOU WILL NOT INCLUDE THE BLOB ITSELF in this query. You
will only include the identifier (PictureID) for the pictures that you
want in this query. In your repeater, you will have an image control
(IMG) whose source (SRC) is set to the URL of your image generator page
(generateimage. aspx) to which you will append a query string that
contains the PictureID of each image. For example,

<img src=<%# "generateimage. aspx?pictureid= " &
DataBinder.Eval (Container.Data Item, "pictureid" )%>

might translate to

<img src=generateima ge.aspx?picture id=25 />

for the first row that the repeater creates and
<img src=generateima ge.aspx?picture id=57 />

for the next row and so on.

Notice that we set the src of each image to an aspx page, not an actual
image file location. As a result, FOR EACH <img> generated by the
repeater, a separate request will be submitted to generateimage.a spx
which will in turn stream the appropriate picture into the html output.
The browser will show a nice table with multiple images from your SQL
Server database.

I hope that this is clear now.

Bill

Nov 19 '05 #6
Bill that was a detailed explanation but can you back it up with a
sample!
That would be great
*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #7
OK Patrick. I threw this together untested, but it's probably very
close.

Bill.
_______________ _____
generateimage.a spx (page declaration only, no html/tags needed)
_______________ ______
<%@ Page Language="vb" AutoEventWireup ="false"
Codebehind="gen erateimage.aspx .vb" Inherits="mypro ject.generateim age"%>
generateimage.a spx.vb (Code behind)
_______________ ______
Imports System.Data.Sql Client
Public Class generateimage
Inherits System.Web.UI.P age

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Request.QuerySt ring("pictureid ") <> "" Then
'Specify the connection string and SQL
Dim strConnect As String = "Enter your connection string
here or get it from your web.config"
Dim strPictureID As String =
Request.QuerySt ring("pictureid ")
Dim strSQL As String = "SELECT PictureBLOB FROM tblPictures
WHERE PictureID=" & strPictureID

'Open the connection and the adapter. Create a dataset
Dim objConn As New SqlConnection(s trConnect)
Dim objAdapt As New SqlDataAdapter( strSQL, objConn)
Dim objDS As New DataSet()
objAdapt.Fill(o bjDS, "PictureTab le")

'Store the BLOB as byte
Dim byteData() As Byte
byteData = objDS.Tables(0) .Rows(0)(0)

'Output the image in the response
Response.Buffer = True
Response.Conten tType = "Image/JPEG"
Response.Binary Write(byteData)
End If
End Sub

End Class

viewpictures.as px
_______________ ________

<%@ Page Language="vb" AutoEventWireup ="false"
Codebehind="vie wpictures.aspx. vb" Inherits="test2 .viewpictures"% >
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>viewpict ures</title>
</head>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<!--repeater for display of images-->
<asp:repeater id="rptpictures " runat="server"
enableviewstate ="false">
<headertemplate >
<table width=100%>
</headertemplate>
<itemtemplate >
<tr>
<td width="50%"><sp an><%# DataBinder.Eval (Container.Data Item,
"PictureDescrip tion")%></span></td>
<td width="50%"><im g src='<%# "generateimage. aspx?pictureid= " &
DataBinder.Eval (Container.Data Item, "PictureID" )%>' /></td>
</tr>
</itemtemplate>
<footertemplate >
</table>
</FooterTemplate>
</asp:repeater>
</form>
</body>
</html>
viewpictures.as px.vb (code behind)
_______________ _____________

Imports System.Data.Sql Client
Public Class viewpictures
Inherits System.Web.UI.P age
Protected WithEvents rptpictures As Repeater

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Specify the connection string and SQL
Dim strConnect As String = "Enter your connection string here
or get it from your web.config"
Dim strPictureID As String = Request.QuerySt ring("pictureid ")
Dim strSQL As String = "SELECT PictureID, PictureDescript ion
FROM tblPictures"

'Open the connection and the adapter. Create a dataset
Dim objConn As New SqlConnection(s trConnect)
Dim objAdapt As New SqlDataAdapter( strSQL, objConn)
Dim objDS As New DataSet()
objAdapt.Fill(o bjDS, "PictureTab le")

'Bind the dataset to the repeater
rptpictures.Dat aSource = objDS
rptpictures.Dat aBind()
End Sub

End Class

Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1280
by: sloan | last post by:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;316495 Radio Buttons Are Not Mutually Exclusive When Used in a Repeater Server Control ... Has 2.0 fixed this bug ?
0
1267
by: sloan | last post by:
BUG: Radio Buttons Are Not Mutually Exclusive When Used in a Repeater Server Control http://support.microsoft.com/default.aspx?scid=kb;EN-US;316495 I programmed up a pretty simple page in 2.0. The issue seems to still be there. Is it supposed to be fixed for 2.0?
9
1440
by: sinbuzz | last post by:
People, Most browsers allow me to suppress viewing of images when I browse a URL. Can this behavior be duplicated by the server? I'd like for my server to detect if a user has image viewing turned off in his browser.
76
2965
by: rcoco | last post by:
Hi all, I'm facing this problem I have images on my website but when I Deploye the website on server the Images are not there I only get the X sign. How can I go about this. Thanks
4
1612
by: surja | last post by:
Hi, I have written a code to download images from a server end desktop, but while running the code ,WTK is showing a runtime error " Create image from Byte array Uncaught exception java/lang/IllegalArgumentException: ". I cannot detect the necessary change I have to make to run my code succesfully.Please anyone can help me to solve this code /code/ import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import...
1
1760
by: praveenkumarvpk | last post by:
Suggest me to store client side images to server side Folder using JSP or Struts Please Help me to find the solution Thank You!
5
2939
by: asharda | last post by:
Hi, I have an ASP.Net application with the back-end as VB.Net. I have a combo control and on the selection changed event of the combo control I need to get the selected image from the database and display it on a Image control on the asp.net page. I get the image from the db as a byte array. Can anyone please help, as to how to show the image on the page in that image control?
0
8382
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5629
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.