User17798125 posted
Hi forum,
I have a gridview that holds an image, but when I click my button to try to find all my info, an error returns with the next error:
System.InvalidCastException: 'No se puede convertir un objeto de tipo 'System.DBNull' al tipo 'System.Byte[]'.'
My WebHandler is this, and the debugger points to the line in yellow.
<%@ WebHandler Language="VB" Class="Handler" %>
Imports System.Web
Imports System.Configuration
Imports System.Data.SqlClient
Public Class Handler
Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim imageid As String = context.Request.QueryString("ImID")
Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("std").ConnectionString)
connection.Open()
Dim command As New SqlCommand("select img from stdplusreport1 where ImageID=" & imageid, connection)
Dim dr As SqlDataReader = command.ExecuteReader()
dr.Read()
context.Response.BinaryWrite(DirectCast(dr(0), [Byte]()))
connection.Close()
context.Response.[End]()
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
I have tried to convert pass to the null what is null, like the next but without success, I cannot find the the correct sentence.
If dr.Read() Then
context.Response.BinaryWrite(DirectCast(dr(0), [Byte]()))
Else
Convert.IsDBNull(dr(0))
End If
Any Ideas?
Thanks! In advance!