http generic handler to show image from database

QEDDave2022

New member
Joined
Mar 18, 2022
Messages
4
Programming Experience
10+
Hello and think you for your time ... I have been fighting this and viewing waaayyy to many code examples because I don't see what's wrong with the following even given I am not that smart. VS error code BC30149.

My code ...
Imports System.Web
Imports System.Web.Services
Imports System.Data.SqlClient
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Color
Imports System.IO
Imports System.Drawing.Printing
Imports System.Globalization
Imports System.Linq

Public Class ImageHandler
Implements System.Web.IHttpHandler

ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property

Public Sub ProcessRequest(ByVal context As HttpContext)
Dim imageId As String = context.Request.QueryString("Id").ToString()
Dim con As SqlConnection = New SqlConnection("Data Source=DESKTOP-6TI2MH9\SQLEXPRESS2017;Initial Catalog=Images;Integrated Security=True;Persist Security Info=False")
Dim cmd As SqlCommand = New SqlCommand("select Image from Images where id=" & imageId, con)
con.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
dr.Read()
context.Response.BinaryWrite(CType(dr(0), Byte()))
context.Response.ContentType = "image/jpg"
context.Response.[End]()
End Sub

End Class

It's called from a button click event
 
A class or structure claims to implement an interface but does not implement a procedure defined by the interface. Every member of the interface must be implemented.
Properties
IsReusable

Methods
ProcessRequest(HttpContext)
Look at your property:
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Then look at your method:
Public Sub ProcessRequest(ByVal context As HttpContext) ???
Can you see what is missing now?
 
Hello!

I have an image control on my ASPX form and am trying to retrieve the image into the control, but get the following error:

Class 'ImageHandler' must implement 'Sub ProcessRequest(context As HttpContext)' for interface 'IHttpHandler'.

I am using the following sample code I found and don't really know what I am doing, and am surprised how difficult it is - perhaps you know an easier way, or what I am doing wrong ...

VB.NET:
Imports System.Web
Imports System.Web.Services
Imports System.Data.SqlClient
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Color
Imports System.IO
Imports System.Drawing.Printing
Imports System.Globalization
Imports System.Linq

Public Class ImageHandler
    Implements System.Web.IHttpHandler

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

    Public Sub ProcessRequest(ByVal context As HttpContext)
        Dim imageId As String = context.Request.QueryString("Id").ToString()
        Dim con As SqlConnection = New SqlConnection("Data Source=DESKTOP-6TI2MH9\SQLEXPRESS2017;Initial Catalog=Images;Integrated Security=True;Persist Security Info=False")
        Dim cmd As SqlCommand = New SqlCommand("select Image from Images where id=" & imageId, con)
        con.Open()
        Dim dr As SqlDataReader = cmd.ExecuteReader()
        dr.Read()
        context.Response.BinaryWrite(CType(dr(0), Byte()))
        context.Response.ContentType = "image/jpg"
        context.Response.[End]()
    End Sub

End Class

************

Thanks for any help!
Dave
 
Last edited by a moderator:
As for the issue, notice that the IsReusable property explicitly states that it implements an interface member while the ProcessRequest method does not? Even now, if you click on the interface name, I think that VS should prompt you to have it add the missing interface members automatically.
 
if you click on the interface name, I think that VS should prompt you to have it add the missing interface members automatically.
I say "I think" because I use ReSharper and it adds some new functionality and overrides some existing functionality in VS. I know that the functionality that I use to do that comes from ReSharper but I'm fairly sure that vanilla VS has something similar.
 
Merged threads
 
Back
Top