Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1090081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:19:10+00:00 2026-05-16T23:19:10+00:00

My instructor gave us example code that is very similiar to the code below.

  • 0

My instructor gave us example code that is very similiar to the code below. I haven’t heard back from him yet and wanted to find out why my code won’t work properly. Could someone give me some advice on what I’m doing wrong or an easier method to display images. Thanks for your time.

<%@ WebHandler Language="VB" Class="images" %>

Imports System
Imports System.Web
Imports System.Data.SqlClient
Public Class images : Implements IHttpHandler

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest


        Dim id As String = context.Request.QueryString("ImageId")
        Dim userId As Integer = 4


        Dim conn As New System.Data.SqlClient.SqlConnection


        Dim cmd As New System.Data.SqlClient.SqlCommand


        conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        cmd.Connection = conn
        cmd.CommandText = "SELECT Image FROM mrg_Image WHERE UserId=@userId"
        cmd.Parameters.AddWithValue("@userId", userId)

        conn.Open()
        Dim file_bytes As Byte() = cmd.ExecuteScalar()        
        Dim file_bytes_stream As New System.IO.MemoryStream(file_bytes)

        'During the build - The next line of code is highlighted green with the error message of, "Parameter is invalid"

        Dim the_image As New System.Drawing.Bitmap(file_bytes_stream)

        context.Response.ContentType = "image/jpg"
        the_image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)        

        conn.Close()
    End Sub

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

End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:19:10+00:00Added an answer on May 16, 2026 at 11:19 pm

    EDIT: Answer (such as it is) in comments. The questioners code is fine…


    Looks fine to me. Are you comitting an implict type conversion between the first and last lines below?

    Dim file_bytes_stream As New System.IO.MemoryStream(file_bytes)
    
    'During the build - The next line of code is highlighted green with the error message of, "Parameter is invalid"
    
    Dim the_image As New System.Drawing.Bitmap(file_bytes_stream)
    

    If you have option explicit set you might need to do…

    Dim file_bytes_memory_stream As New System.IO.MemoryStream(file_bytes)
    
    Dim file_bytes_stream as System.IO.Stream = DirectCast(file_bytes_memory_stream, System.IO.Stream)
    
    Dim the_image As New System.Drawing.Bitmap(file_bytes_stream)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following piece of code was given to us from our instructor so we
I'm working on a project for school and the instructor insists that all code
My instructor gave us some sample code and she used a \a1 \a2 \a3
A friend of mine wanted help learning to program, so he gave me all
I am creating a DLL using the code provided to us by my instructor.
I talked to my instructor the other day and asked him this question. He
I have this code provided by my instructor. I am supposed to fix it
From my course instructor, he has repeatedly emphasized and asked us not to use
Our Java instructor always asks us to prove that Every java program is Object
This is the driver code provided by my instructor, It isn't meant to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.