Home All Groups Group Topic Archive Search About

How to save iamge in database?

Author
31 Jul 2006 6:23 AM
Ishtiaque Ahmed Memon
Dear All

Can anyone tell me how to save an JPEG image in a database table field?

Below is the code that I have wrote but it gives an error:
System.InvalidCastException
Object must implement IConvertible

DatabaseAccess.SqlConnection.Open()

picDataAdapter.InsertCommand = New SqlCommand("INSERT INTO TheImage(AppNo,
theImage) VALUES(@appno, @theImage)", DatabaseAccess.SqlConnection)

picDataAdapter.InsertCommand.Parameters.Add("@appno", SqlDbType.Int).Value =
AppNo

picDataAdapter.InsertCommand.Parameters.Add("@theImage", SqlDbType.Image,
7000).Value = MyImage

picDataAdapter.InsertCommand.ExecuteNonQuery()

DatabaseAccess.SqlConnection.Close()

TheImage table has two fields:

AppNo int

theImage Image

myImage is of Image type

Waiting for reply... Thanks in advance

Regards

Ishtiaque Ahmed Memon

Author
31 Jul 2006 10:53 AM
Ken Tucker [MVP]
Hi,

        You need to convert the image to a byte array to save it in a
database.  There is an example in this tip.

http://www.vb-tips.com/dbpages.aspx?ID=0bf3f72d-b722-459d-8a46-38b5a2f7fdf0

Ken
-------------------
Show quoteHide quote
"Ishtiaque Ahmed Memon" <ishtiaqu***@yahoo.com> wrote in message
news:ObxCnnGtGHA.1304@TK2MSFTNGP06.phx.gbl...
> Dear All
>
> Can anyone tell me how to save an JPEG image in a database table field?
>
> Below is the code that I have wrote but it gives an error:
> System.InvalidCastException
> Object must implement IConvertible
>
> DatabaseAccess.SqlConnection.Open()
>
> picDataAdapter.InsertCommand = New SqlCommand("INSERT INTO TheImage(AppNo,
> theImage) VALUES(@appno, @theImage)", DatabaseAccess.SqlConnection)
>
> picDataAdapter.InsertCommand.Parameters.Add("@appno", SqlDbType.Int).Value
> =
> AppNo
>
> picDataAdapter.InsertCommand.Parameters.Add("@theImage", SqlDbType.Image,
> 7000).Value = MyImage
>
> picDataAdapter.InsertCommand.ExecuteNonQuery()
>
> DatabaseAccess.SqlConnection.Close()
>
> TheImage table has two fields:
>
> AppNo int
>
> theImage Image
>
> myImage is of Image type
>
> Waiting for reply... Thanks in advance
>
> Regards
>
> Ishtiaque Ahmed Memon
>
>
>
>
>