jimSabandalx
jimSabandalx

Reputation: 27

Unable to cast object of type 'system.byte ' to type 'system.iconvertible in vb.net

The Error says that Unable to cast object of type 'system.byte[] ' to type 'system.iconvertible. What should I do? Anyone....

            Dim ms1 As New MemoryStream
            Dim ms2 As New MemoryStream
            Dim data1 As Byte()
            Dim data2 As Byte()



            PictureBox1.Image.Save(ms1, ImageFormat.Jpeg)
            PictureBox2.Image.Save(ms2, ImageFormat.Jpeg)

            data1 = ms1.ToArray()
            data2 = ms2.ToArray()


            cmd.CommandType = CommandType.Text

            cmd.Parameters.AddWithValue("@signature", SqlDbType.VarBinary).Value = data2
            cmd.Parameters.AddWithValue("@picture", SqlDbType.VarBinary).Value = data1

            Using sda As New MySqlDataAdapter(cmd)
                Try
                    con.Open()
                    cmd.ExecuteNonQuery()
                    MsgBox("Data Inserted!")
                Catch ex As Exception
                    MsgBox(ex.Message)
                    con.Close()

                End Try

Upvotes: 1

Views: 805

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54417

The way you are adding your parameters is wrong. You're mixing up the use of Add and AddWithValue. This:

cmd.Parameters.AddWithValue("@signature", SqlDbType.VarBinary).Value = data2

should be either this:

cmd.Parameters.AddWithValue("@signature", data2)

or this:

cmd.Parameters.Add("@signature", SqlDbType.VarBinary).Value = data2

Upvotes: 1

Related Questions