When I try save information into the database without picture, i get this error:System.NullReferenceException' occurred in ...exe
these are my codes:
Dim bytes() As Byte = ms.ToArray
Dim UploadImage As Bitmap = PictureBox.BackgroundImage
Dim stream As New MemoryStream()
PictureBox.BackgroundImage.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim picture() As Byte = stream.GetBuffer()
stream.Close()
Dim ds As DataSet = New DataSet()
Dim str As String
str = "insert into Staff_Information(EmpID,Fname,Oname,Lname,Date_hired,Branch,Department,Grade,Pictures) values (@EmpID,@Fname,@Oname,@Lname,@Date_hired,@Branch,@Department,@Grade,@Pictures)"
cmd = New SqlCommand(str, con)
con.Open()
cmd.Parameters.AddWithValue("@EmpID", txtempID.Text)
cmd.Parameters.AddWithValue("@Fname", txtfname.Text)
cmd.Parameters.AddWithValue("@Oname", txtothername.Text)
cmd.Parameters.AddWithValue("@Lname", txtlname.Text)
cmd.Parameters.AddWithValue("@Date_hired", dtpempl.Value)
cmd.Parameters.AddWithValue("@Branch", txtbranch.Text)
cmd.Parameters.AddWithValue("@Department", txtdepartment.Text)
cmd.Parameters.AddWithValue("@Grade", txtgrade.Text)
cmd.Parameters.AddWithValue("@Pictures", picture)
cmd.ExecuteNonQuery()
MsgBox("Successful Saved")
con.Close()
cmd.Dispose()
What I have tried:
Tried
Try
Catch ex As Exception
'End Try
Option but nothing happens
Please i need help