Dear Experts
I use following codes to display image from sql server.
On this line of codes
this error messages appears
How to get rid of this error message.
This message appears because image column is NULL.
Please Help
I use following codes to display image from sql server.
On this line of codes
VB.NET:
Dim ms As New IO.MemoryStream(CType(row("user_img"), Byte()))Dim ms As New IO.MemoryStream(CType(row("user_img"), Byte()))
this error messages appears
VB.NET:
Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'.Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'.
This message appears because image column is NULL.
VB.NET:
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 dt.Load(dr) 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 IfDim 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
dt.Load(dr)
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