无法将类型为'system.byte'的对象强制转换为在vb.net

时间:2017-11-09 05:01:08

标签: vb.net

错误说无法将类型为'system.byte []'的对象强制转换为'system.iconvertible'。我该怎么办?任何人....

            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

1 个答案:

答案 0 :(得分:0)

添加参数的方式是错误的。您混淆了AddAddWithValue的使用。这样:

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

应该是这样的:

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

或者这个:

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