简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM