473,386 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

fetch image data from access database to picture box in vb.net

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()
Nov 20 '05 #1
17 18702
Cor
Hi Abhisek,

It has mostly to do with the enclosing from a image in an access file in an
object.

I once copied some code and have tried that to paste in your code, give it a
try?
(You have yourself to set it right in the try block again)

I did not test it, I just pasted it in, so please tell if it did work, than
I know that also?

Cor
\\\
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) & "'"
connection.open
Dim dr As OleDbDataReader =
cmd.ExecuteReader(CommandBehavior.SequentialAccess )
dr.Read()
Dim FieldLen As Integer = dr.Item(1).ToString.Length
Dim a(FieldLen - 1) As Byte
Dim startIndex As Integer = 0
dim RetVal as long = dr.GetBytes(1, startIndex, a, 0, a.Length)
dr.Close()
connection.Close()
connection.dispose
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

Nov 20 '05 #2
no it is not working that way also.
i have also tried the code given on microsoft site given below but it
also gives me the same error. am i missing somthing else. please help

Dim da As New OleDb.OleDbDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, "MASTER")
Dim c As Integer = ds.Tables("MASTER").Rows.Count
If c > 0 Then
Dim bytBLOBData() As Byte = _
ds.Tables("MASTER").Rows(c - 1)("Image")
Dim stmBLOBData As New MemoryStream(bytBLOBData)
pbImage.Image = Image.FromStream(stmBLOBData)
end if
Nov 20 '05 #3
Cor
Hi Abhishek,

This code is for a standard blob not embeded in an ole object.
I do not know if you have that, however you can try to change this. It is
also better to always use Option Strict On, than this kind of problems (when
it is that) shows earlier

Ctype(ds.Tables("MASTER").Rows(c - 1)("Image"),Byte())

I hope this Helps?

Cor

Nov 20 '05 #4
On 3 Apr 2004 23:52:42 -0800, ab******@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 ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #5
On 3 Apr 2004 23:52:42 -0800, ab******@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 ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #6
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 <Us***********************@swspectrum.com> wrote in message news:<h0********************************@4ax.com>. ..
On 3 Apr 2004 23:52:42 -0800, ab******@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 ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 20 '05 #7
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 <Us***********************@swspectrum.com> wrote in message news:<h0********************************@4ax.com>. ..
On 3 Apr 2004 23:52:42 -0800, ab******@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 ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 20 '05 #8
On 5 Apr 2004 16:50:45 -0700, ab******@netscape.net (Abhishek) wrote:

¤ 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?

I'm trying to determine whether the image was stored as an OLE object, which would mean that it
contains OLE headers. This makes the retrieval somewhat more difficult.

Do you know whether it was stored as an OLE object or was it written as a binary stream from a file?
Also, what type of image is this? BMP? JPG?
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #9
On 5 Apr 2004 16:50:45 -0700, ab******@netscape.net (Abhishek) wrote:

¤ 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?

I'm trying to determine whether the image was stored as an OLE object, which would mean that it
contains OLE headers. This makes the retrieval somewhat more difficult.

Do you know whether it was stored as an OLE object or was it written as a binary stream from a file?
Also, what type of image is this? BMP? JPG?
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #10
I think that the file is stored as ole object. because when i stored the
retrived data in a file it showed me the extra header.
so how is it possible to retrive the ole image from access in dot net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #11
I think that the file is stored as ole object. because when i stored the
retrived data in a file it showed me the extra header.
so how is it possible to retrive the ole image from access in dot net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #12
On Thu, 08 Apr 2004 10:20:39 -0700, Abhishek Trivedi <ab******@netscape.net> wrote:

¤ I think that the file is stored as ole object. because when i stored the
¤ retrived data in a file it showed me the extra header.
¤ so how is it possible to retrive the ole image from access in dot net
¤

Well each image type will likely have a different OLE header. Does each row have the same image type
and if so what is the image type? (e.g. BMP, JPG, etc.)
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #13
On Thu, 08 Apr 2004 10:20:39 -0700, Abhishek Trivedi <ab******@netscape.net> wrote:

¤ I think that the file is stored as ole object. because when i stored the
¤ retrived data in a file it showed me the extra header.
¤ so how is it possible to retrive the ole image from access in dot net
¤

Well each image type will likely have a different OLE header. Does each row have the same image type
and if so what is the image type? (e.g. BMP, JPG, etc.)
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #14
yes all the images are of the same type i.e. *.bmp

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #15
yes all the images are of the same type i.e. *.bmp

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #16
can anybody solve my problem please. i have to show images stored in
access database(ole column type) in visual basic .net picturebox
control.thanx
Nov 20 '05 #17
can anybody solve my problem please. i have to show images stored in
access database(ole column type) in visual basic .net picturebox
control.thanx
Nov 20 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jack | last post by:
Hi. I wanted to save image from the form in my accss database. there is one picture box on form which loads the picture from the harddisk . i want this picture to store in my database .. thanks...
1
by: Eric Keung | last post by:
Hi all, my case is I want to get an image from access database and I just know it's "OLE object" field type at access I also don't know how to insert it into access here is my code and it just...
20
by: Abhishek | last post by:
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...
1
by: Mahbubul Alam | last post by:
Hi Any one can tell me how to fetch image data from Access database to VB.NET. Mahbub
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.