when I search for record using "empid" image does not load into picturebox. An error occurs. I am using VS2013 and datatype for image is "Varbinary(max)"
or should I use "Image Datatye" in sql. Which is Better ?
----------------------------------------------------------------
Error:
----------------------------------------------------------------
An unhandled exception of type 'System.InvalidCastException' occurred in Employee Management System.exe
Additional information: Unable to cast object of type 'System.Byte[]' to type 'System.Drawing.Image'.
-------------------------------------------------------------------
code:
-------------------------------------------------------------------
try
con.Open()
ss = "SELECT * from emp_master WHERE empid=" & txtempid.Text & ""
com = New SqlCommand(ss, con)
dr = com.ExecuteReader()
dr.Read()
If dr.HasRows = True Then
txtempid.Text = dr(0)
txtename.Text = dr(1)
txtpfno.Text = dr(2)
dtpdob.Value = dr(3)
If dr(4) = "Male" Then
rbmale.Checked = True
ElseIf dr(4) = "Female" Then
rbfemale.Checked = True
End If
txtcontact.Text = dr(5)
txtemail.Text = dr(6)
dtpdoj.Value = dr(7)
txtaddress.Text = dr(8)
txtedu.Text = dr(9)
txtNation.Text = dr(10)
cmb_Bloodgrp.Text = dr(11)
txtdesig.Text = dr(12)
txtexp.Text = dr(13)
txtsalary.Text = dr(14)
txtdept.Text = dr(15)
PictureBox1.Image = dr(16)
Cmb_utype.Text = dr(17)
Else
MsgBox("No Record Found !", MsgBoxStyle.OkOnly, MsgBoxStyle.Exclamation)
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
dr.Close()
con.Close()
End Try