Dear Experts

I use following codes to display image from sql server.

On this line of codes

Dim ms As New IO.MemoryStream(CType(row("user_img"), Byte()))

this error messages appears

Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'.

How to get rid of this error message.
This message appears because image column is NULL.

Dim cmd As New SqlClient.SqlCommand("select user_img from login where user_sno =" & Val(Me.TextBox1.Text), con)
        Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader()
        Dim dt As New DataTable
        Dim row As DataRow = dt.Rows(0)

        If dt.Rows.Count > 0 Then

            Dim ms As New IO.MemoryStream(CType(row("user_img"), Byte()))
            Dim img As Image = Image.FromStream(ms)
            PictureBox1.Image = img
        End If

Please Help

I tried to convince you that you had a null value in another thread:

I guess now you agree it is in fact a null? Please continue with the older thread instead of this one since it is the same question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.