How do I construct a Image Handler for Multiple Images in a Database?

I am trying to see my uploaded images but I can only see one when I use my handler. I tried adding ("Image, Image2") into the Handler, but I received an error. I have truly exhausted all my time, and I need help. Im sure I am not following the rules regarding my format, so I need some help.

By the way, when the page is launched I can see images only in the "Image" column.

Thank you very much,
Sparilla
'Here is the Aspx Page I am Uploading with
 
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
<script runat="server">
 
    Protected Sub dlstImages_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
 
    End Sub
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Photo Gallery</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <asp:DataList
        id="dlstImages"
        DataSourceID="srcImages"
        RepeatColumns="3"
        Runat="server" onselectedindexchanged="dlstImages_SelectedIndexChanged" 
            BorderColor="Black" BorderWidth="1px">
        <ItemTemplate>
        <asp:Image ID="Image1"
            ImageUrl='<%# String.Format("DynamicImage.ashx?id={0}", Eval("Id")) %>'
            Width="250"
            Runat="server" />
        <br />
        <%# Eval("Description") %>
    </ItemTemplate>
    </asp:DataList>
         
    <hr />
 
    <asp:FormView
        id="frmImage"
        DataSourceID="srcImages"
        DefaultMode="Insert"
        Runat="server">
        <InsertItemTemplate>
        <asp:Label
            id="lblImage"
            Text="Upload Image:"
            AssociatedControlId="upImage"
            Runat="server" />
        <br />    
        <asp:FileUpload
            id="upImage"
            FileBytes='<%# Bind("Image") %>'
            Runat="server" />
        
        <br /><br />
        
        <asp:Label
            id="lblDescription"
            Text="Description:"
            AssociatedControlID="txtDescription"
            Runat="server" />
        <br />    
        <asp:TextBox
            id="txtDescription"
            Text='<%# Bind("Description") %>'
            TextMode="MultiLine"
            Columns="50"
            Rows="2"
            Runat="server" />    
        
        <br /><br />
        
        <asp:Button
            id="btnInsert"
            Text="Add Image"
            CommandName="Insert"
            Runat="server" />    
        </InsertItemTemplate>
    </asp:FormView>    
        
   
    
    <asp:SqlDataSource
        id="srcImages"
        SelectCommand="SELECT ID,Description FROM Images"
        InsertCommand="INSERT Images (Image,Description)
            VALUES (@Image,@Description)"
        ConnectionString="<%$ ConnectionStrings:Images %>"
        Runat="server" />
    
    
        <br />
        <br />
    
    
    </div>
    </form>
</body>
</html>
 
 
 
 
 
 
'This is the Handler 
 
 
<%@ WebHandler Language="VB" Class="DynamicImage" %>
 
Imports System.Data
Imports System.Web
Imports System.Web.Configuration
Imports System.Web.UI
Imports System.Web.UI.WebControls
 
''' <summary>
''' Displays an image corresponding to the Id passed
''' in a query string field
''' </summary>
Public Class DynamicImage
	 Implements IHttpHandler
 
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        ' Get the Id of the image to display
        Dim imageId As String = context.Request.QueryString("Id")
 
        ' Use SqlDataSource to grab image bytes
        Dim src As SqlDataSource = New SqlDataSource()
        src.ConnectionString = WebConfigurationManager.ConnectionStrings("Images").ConnectionString
        src.SelectCommand = "SELECT Image FROM Images WHERE Id=" + imageId
        
       
 
        ' Return a DataView
        Dim view As DataView = CType(src.Select(DataSourceSelectArguments.Empty), DataView)
        context.Response.BinaryWrite(CType(view(0)("Image"), Byte()))
 
        ' Return a DataReader
        'src.DataSourceMode = SqlDataSourceMode.DataReader
        'Dim reader As IDataReader = CType(src.Select(DataSourceSelectArguments.Empty), IDataReader)
        'reader.Read()
        'context.Response.BinaryWrite(CType(reader("Image"), Byte()))
        'reader.Close()
 
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
 
End Class
 
 
 
'Here is the database
 
Id              Int               Dont Allow Nulls
Image          varbinary(MAX)    Allowed Nulls
Description     nvarchar(MAX)    Allowed Nulls
Image2          varbinary(MAX)    Allowed Nulls
Description2     nvarchar(MAX)    Allowed Nulls
Image3          varbinary(MAX)    Allowed Nulls
Description3     nvarchar(MAX)    Allowed Nulls

Open in new window

LVL 1
sparillaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
When you processed multiple images, did you create a loop block to repeat the steps multiple times?

Bob
0
sparillaAuthor Commented:
No i didnt. Do you have an example of how that could be done Bob?
0
Bob LearnedCommented:
Where you looking to pass multiple IDs in the QueryString values?

Default.aspx?id=1720, 310, 1312

Bob
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

sparillaAuthor Commented:
I wanted to pass all IDs if possible, but it's not the ID im having a problem with. I can only get the first image to show, and the second one will not.
0
Bob LearnedCommented:
This is what I would try:
Imports System.Data
Imports System.Web.Configuration
 
Public Class DynamicImage
  Implements IHttpHandler
 
  Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
 
    ' Get the Id of the image to display
    If context.Request.QueryString("id") IsNot Nothing Then
      Dim imageIdList As String = context.Request.QueryString("Id")
 
      Dim src As New SqlDataSource()
      src.ConnectionString = WebConfigurationManager.ConnectionStrings("Images").ConnectionString
 
      For Each imageId As String In imageIdList.Split(","c)
 
        ' Use SqlDataSource to grab image bytes
        src.SelectCommand = "SELECT Image FROM Images WHERE Id=" + imageId.Trim()
 
        ' Return a DataView
        Dim view As DataView = CType(src.Select(DataSourceSelectArguments.Empty), DataView)
 
        If view.Count > 0 Then
          context.Response.BinaryWrite(CType(view(0)("Image"), Byte()))
        End If
 
      Next imageId
 
    End If
 
  End Sub
 
  Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
    Get
      Return False
    End Get
  End Property
 
End Class

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sparillaAuthor Commented:
This worked out perfectly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.