The Image is Stored in access database in OLE Type of Column. it was
stored using the access form wizard.
can the image data retrieved from access be in wrong format?
Paul Clement <UseAdddressAtEndofMessage@swspectrum.com> wrote in message news:<h07370dvmec7u4ug9ons2s0gbij4psll28@4ax.com>. ..[color=blue]
> On 3 Apr 2004 23:52:42 -0800,
abhitriv@netscape.net (Abhishek) wrote:
>
> ¤ can anybody tell how to fetch image from database(access) to the
> ¤ visual basic picture box control. the code i have been using is as
> ¤ below but it gives me invalid paramter error....
> ¤
> ¤ Dim connection As New OleDb.OleDbConnection()
> ¤ Dim cmd As New OleDb.OleDbCommand()
> ¤ cmd.CommandText = "select ID,Name,Description,Image from
> ¤ MASTER where ID like '" & Trim(cmbID.Text) & "'"
> ¤ cmd.Connection = connection
> ¤ Dim myReader As OleDb.OleDbDataReader
> ¤ cmd.CommandType = CommandType.Text
> ¤ openOLEDBconnection(SQL_CONNECTION_STRING, connection)
> ¤ myReader =
> ¤ cmd.ExecuteReader(CommandBehavior.CloseConnection)
> ¤ While myReader.Read()
> ¤ txtId.Text = myReader(0)
> ¤ txtName.Text = myReader(1).ToString()
> ¤ txtDescription.Text = myReader(2).ToString()
> ¤ If Not IsDBNull(myReader(3)) Then
> ¤ Try
> ¤ Try
> ¤ Dim a(myReader.GetBytes(3, 0, Nothing, 0,
> ¤ Integer.MaxValue) - 1) As Byte
> ¤ myReader.GetBytes(3, 0, a, 0, a.Length)
> ¤ Dim b As New MemoryStream(a)
> ¤ With pbImage
> ¤ .Image = image.FromStream(b)
> ¤ .SizeMode =
> ¤ PictureBoxSizeMode.CenterImage
> ¤ .BorderStyle = BorderStyle.Fixed3D
> ¤ End With
> ¤ Catch exp As Exception
> ¤ MsgBox(exp.Message)
> ¤ End Try
> ¤ Catch exp As System.InvalidCastException
> ¤ MsgBox(exp.Message)
> ¤ End Try
> ¤ End If
> ¤ End While
> ¤ myReader.Close()
>
> Couple of questions. What is the Access data type of the column that this image is stored in? How
> was is originally stored?
>
>
> Paul ~~~
pclement@ameritech.net
> Microsoft MVP (Visual Basic)[/color]