Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Shy the error is giving

my cs coading Handler.ashx is given below

C#
<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data.OracleClient;
using System.Data;
using System.IO;
using System.Web.UI.WebControls;

public class Handler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        string id = context.Request.QueryString["ImID"];
        if (id == string.Empty)
        {
            return;
        }
        else
        {
            OracleConnection connection = new OracleConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["OracleConnect1"].ConnectionString);
            connection.Open();
            OracleCommand command = new OracleCommand("select CTD_SHAPE_IMG from  V_CAB_TAG_DTLS where CTD_SHAPE_ID='" + id + "'", connection);
            OracleDataReader dr = command.ExecuteReader();
            dr.Read();
            string str = Convert.ToString(dr["CTD_SHAPE_IMG"]);
            if (Convert.ToString(str) != null)
            {
                context.Response.BinaryWrite((Byte[])dr[0]);
                connection.Close();
                context.Response.End();
            }
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 3-May-12 21:22pm
v2

1 solution

No, you can't cast a null entry to a byte[].

Your image as stored in your DB is null, so the DB returns DBNull.Value. You need to check and only cast it if it isn't null. If it is null, I would load a default graphics (a non-image available picture) and send that instead.

It may be that you haven't stored the image, or you may be returning the wrong image or you ID may be wrong when you read it from the query string.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900