problem to insert an image into a database using programatically

  • 10 years ago

    Hi everyone

    I am trying to insert an image into a database table field using sqlCommand object method ExecuteNonQuery().  My SQL statement has a parameter to assign the image. I keep getting an error saying "the object need to implement IConvertable". I don't know why?

    any help !

    'i wrote like this.........

    sql = "UPDATE tablename SET field1 = @image"

    dim picture as image = picturebox1.image

    Try

        SqlCommand(sql, cn)

       Dim par As New SqlParameter("@picture", SqlDbType.Image)

       par.Value = picture

       cmd.Parameters.Add(par)

       cmd.ExecuteNonQuery()

    Catch e As InvalidCastException

       MessageBox.Show(e.Message)

    End try

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.”