No se puede emitir un objeto de tipo 'System.DBNull' para escribir 'System.Byte []'.

cuando trato de seleccionar un elemento en el ListView que no tiene imagen en mi base de datos, este error muestraUnable to cast object of type 'System.DBNull' to type 'System.Byte[]'. Traté de poner un código comoisDBNull oDBNull Pero es aplicable.

Aquí está mi código:

Private Sub LvPeople_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LvPeople.SelectedIndexChanged
        If LvPeople.SelectedItems.Count > 0 Then
            Dim connstring As String = "server = localhost; user id = root; database = db; password = root"
            Dim Sql As String = "select * from candidate where idn='" & LvPeople.SelectedItems(0).Text & "'"
            Dim conn As New MySqlConnection(connstring)
            Dim cmd As New MySqlCommand(Sql, conn)
            Dim dr As MySqlDataReader = Nothing
            conn.Open()
            dr = cmd.ExecuteReader()
            dr.Read()
            Dim imagebytes As Byte() = CType(dr("photo"), Byte())
            Using ms As New IO.MemoryStream(imagebytes)
                PictureBox1.Image = Image.FromStream(ms)
                PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            End Using
            conn.Close()
        End If
End Sub
End Class

El error señala aquí:

Dim imagebytes As Byte() = CType(dr("photo"), Byte())

Realmente no tengo idea de qué poner aquí. Solo un novato aquí.

Respuestas a la pregunta(2)

Su respuesta a la pregunta