Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15670

Image Empty

$
0
0
Hi,

I have the following code that works fine, but ONLY fails when no image is uploaded to PictureBox1

Code:

Dim command As New SqlCommand("INSERT INTO dbo.tbllandlords (firstName, lastName, landlordfullname, telephone, email, physicaladdress, city, nationalid, KRAPIN, copyID) VALUES (@firstName, @lastName, @landlordfullname, @telephone, @email, @physicaladdress, @city, @nationalid, @KRAPIN, @copyID)", conn)

                Dim ms As New MemoryStream
                PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)

                command.Parameters.Add("@firstname", SqlDbType.VarChar).Value = TxtFName.Text
                command.Parameters.Add("@lastname", SqlDbType.VarChar).Value = TxtLName.Text
                command.Parameters.Add("@landlordfullname", SqlDbType.VarChar).Value = TxtFName.Text & " " & TxtLName.Text
                command.Parameters.Add("@telephone", SqlDbType.NVarChar).Value = TxtTel.Text
                command.Parameters.Add("@email", SqlDbType.NVarChar).Value = TxtEmail.Text
                command.Parameters.Add("@physicaladdress", SqlDbType.NVarChar).Value = TxtAddress1.Text
                command.Parameters.Add("@city", SqlDbType.VarChar).Value = cmbCity.Text
                command.Parameters.Add("@nationalID", SqlDbType.NVarChar).Value = TxtNationalID.Text
                command.Parameters.Add("@KRAPIN", SqlDbType.NVarChar).Value = TxtPIN.Text
                command.Parameters.Add("@copyID", SqlDbType.Image).Value = ms.ToArray()

                command.ExecuteNonQuery()
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Information, "RCMS")
            End Try

            MsgBox("New landlord has been added", MsgBoxStyle.Information, "RCMS")


Offensive line:

Code:

PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
Error states:

Code:

System.NullReferenceException: 'Object reference not set to an instance of an object.'
At the database level - copyId is a datatype image and allows NULL

Thanks

Viewing all articles
Browse latest Browse all 15670

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>