473,626 Members | 3,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.OleDbConn ection()
Dim cmd As New OleDb.OleDbComm and()
cmd.CommandText = "select ID,Name,Descrip tion,Image from
MASTER where ID like '" & Trim(cmbID.Text ) & "'"
cmd.Connection = connection
Dim myReader As OleDb.OleDbData Reader
cmd.CommandType = CommandType.Tex t
openOLEDBconnec tion(SQL_CONNEC TION_STRING, connection)
myReader =
cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion)
While myReader.Read()
txtId.Text = myReader(0)
txtName.Text = myReader(1).ToS tring()
txtDescription. Text = myReader(2).ToS tring()
If Not IsDBNull(myRead er(3)) Then
Try
Try
Dim a(myReader.GetB ytes(3, 0, Nothing, 0,
Integer.MaxValu e) - 1) As Byte
myReader.GetByt es(3, 0, a, 0, a.Length)
Dim b As New MemoryStream(a)
With pbImage
.Image = image.FromStrea m(b)
.SizeMode =
PictureBoxSizeM ode.CenterImage
.BorderStyle = BorderStyle.Fix ed3D
End With
Catch exp As Exception
MsgBox(exp.Mess age)
End Try
Catch exp As System.InvalidC astException
MsgBox(exp.Mess age)
End Try
End If
End While
myReader.Close( )
Nov 20 '05 #1
17 18728
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.OleDbConn ection()
Dim cmd As New OleDb.OleDbComm and()
cmd.CommandText = "select ID,Name,Descrip tion,Image from
MASTER where ID like '" & Trim(cmbID.Text ) & "'"
connection.open
Dim dr As OleDbDataReader =
cmd.ExecuteRead er(CommandBehav ior.SequentialA ccess)
dr.Read()
Dim FieldLen As Integer = dr.Item(1).ToSt ring.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.Clos e()
connection.disp ose
Dim b As New MemoryStream(a)
With pbImage
.Image = image.FromStrea m(b)
.SizeMode =
PictureBoxSizeM ode.CenterImage
.BorderStyle = BorderStyle.Fix ed3D
End With
Catch exp As Exception
MsgBox(exp.Mess age)
End Try
Catch exp As System.InvalidC astException
MsgBox(exp.Mess age)
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.OleDbData Adapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, "MASTER")
Dim c As Integer = ds.Tables("MAST ER").Rows.Cou nt
If c > 0 Then
Dim bytBLOBData() As Byte = _
ds.Tables("MAST ER").Rows(c - 1)("Image")
Dim stmBLOBData As New MemoryStream(by tBLOBData)
pbImage.Image = Image.FromStrea m(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"),Byt e())

I hope this Helps?

Cor

Nov 20 '05 #4
On 3 Apr 2004 23:52:42 -0800, ab******@netsca pe.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.OleDbConn ection()
¤ Dim cmd As New OleDb.OleDbComm and()
¤ cmd.CommandText = "select ID,Name,Descrip tion,Image from
¤ MASTER where ID like '" & Trim(cmbID.Text ) & "'"
¤ cmd.Connection = connection
¤ Dim myReader As OleDb.OleDbData Reader
¤ cmd.CommandType = CommandType.Tex t
¤ openOLEDBconnec tion(SQL_CONNEC TION_STRING, connection)
¤ myReader =
¤ cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion)
¤ While myReader.Read()
¤ txtId.Text = myReader(0)
¤ txtName.Text = myReader(1).ToS tring()
¤ txtDescription. Text = myReader(2).ToS tring()
¤ If Not IsDBNull(myRead er(3)) Then
¤ Try
¤ Try
¤ Dim a(myReader.GetB ytes(3, 0, Nothing, 0,
¤ Integer.MaxValu e) - 1) As Byte
¤ myReader.GetByt es(3, 0, a, 0, a.Length)
¤ Dim b As New MemoryStream(a)
¤ With pbImage
¤ .Image = image.FromStrea m(b)
¤ .SizeMode =
¤ PictureBoxSizeM ode.CenterImage
¤ .BorderStyle = BorderStyle.Fix ed3D
¤ End With
¤ Catch exp As Exception
¤ MsgBox(exp.Mess age)
¤ End Try
¤ Catch exp As System.InvalidC astException
¤ MsgBox(exp.Mess age)
¤ 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******@amerit ech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #5
On 3 Apr 2004 23:52:42 -0800, ab******@netsca pe.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.OleDbConn ection()
¤ Dim cmd As New OleDb.OleDbComm and()
¤ cmd.CommandText = "select ID,Name,Descrip tion,Image from
¤ MASTER where ID like '" & Trim(cmbID.Text ) & "'"
¤ cmd.Connection = connection
¤ Dim myReader As OleDb.OleDbData Reader
¤ cmd.CommandType = CommandType.Tex t
¤ openOLEDBconnec tion(SQL_CONNEC TION_STRING, connection)
¤ myReader =
¤ cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion)
¤ While myReader.Read()
¤ txtId.Text = myReader(0)
¤ txtName.Text = myReader(1).ToS tring()
¤ txtDescription. Text = myReader(2).ToS tring()
¤ If Not IsDBNull(myRead er(3)) Then
¤ Try
¤ Try
¤ Dim a(myReader.GetB ytes(3, 0, Nothing, 0,
¤ Integer.MaxValu e) - 1) As Byte
¤ myReader.GetByt es(3, 0, a, 0, a.Length)
¤ Dim b As New MemoryStream(a)
¤ With pbImage
¤ .Image = image.FromStrea m(b)
¤ .SizeMode =
¤ PictureBoxSizeM ode.CenterImage
¤ .BorderStyle = BorderStyle.Fix ed3D
¤ End With
¤ Catch exp As Exception
¤ MsgBox(exp.Mess age)
¤ End Try
¤ Catch exp As System.InvalidC astException
¤ MsgBox(exp.Mess age)
¤ 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******@amerit ech.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************ ***********@sws pectrum.com> wrote in message news:<h0******* *************** **********@4ax. com>...
On 3 Apr 2004 23:52:42 -0800, ab******@netsca pe.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.OleDbConn ection()
¤ Dim cmd As New OleDb.OleDbComm and()
¤ cmd.CommandText = "select ID,Name,Descrip tion,Image from
¤ MASTER where ID like '" & Trim(cmbID.Text ) & "'"
¤ cmd.Connection = connection
¤ Dim myReader As OleDb.OleDbData Reader
¤ cmd.CommandType = CommandType.Tex t
¤ openOLEDBconnec tion(SQL_CONNEC TION_STRING, connection)
¤ myReader =
¤ cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion)
¤ While myReader.Read()
¤ txtId.Text = myReader(0)
¤ txtName.Text = myReader(1).ToS tring()
¤ txtDescription. Text = myReader(2).ToS tring()
¤ If Not IsDBNull(myRead er(3)) Then
¤ Try
¤ Try
¤ Dim a(myReader.GetB ytes(3, 0, Nothing, 0,
¤ Integer.MaxValu e) - 1) As Byte
¤ myReader.GetByt es(3, 0, a, 0, a.Length)
¤ Dim b As New MemoryStream(a)
¤ With pbImage
¤ .Image = image.FromStrea m(b)
¤ .SizeMode =
¤ PictureBoxSizeM ode.CenterImage
¤ .BorderStyle = BorderStyle.Fix ed3D
¤ End With
¤ Catch exp As Exception
¤ MsgBox(exp.Mess age)
¤ End Try
¤ Catch exp As System.InvalidC astException
¤ MsgBox(exp.Mess age)
¤ 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******@amerit ech.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************ ***********@sws pectrum.com> wrote in message news:<h0******* *************** **********@4ax. com>...
On 3 Apr 2004 23:52:42 -0800, ab******@netsca pe.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.OleDbConn ection()
¤ Dim cmd As New OleDb.OleDbComm and()
¤ cmd.CommandText = "select ID,Name,Descrip tion,Image from
¤ MASTER where ID like '" & Trim(cmbID.Text ) & "'"
¤ cmd.Connection = connection
¤ Dim myReader As OleDb.OleDbData Reader
¤ cmd.CommandType = CommandType.Tex t
¤ openOLEDBconnec tion(SQL_CONNEC TION_STRING, connection)
¤ myReader =
¤ cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion)
¤ While myReader.Read()
¤ txtId.Text = myReader(0)
¤ txtName.Text = myReader(1).ToS tring()
¤ txtDescription. Text = myReader(2).ToS tring()
¤ If Not IsDBNull(myRead er(3)) Then
¤ Try
¤ Try
¤ Dim a(myReader.GetB ytes(3, 0, Nothing, 0,
¤ Integer.MaxValu e) - 1) As Byte
¤ myReader.GetByt es(3, 0, a, 0, a.Length)
¤ Dim b As New MemoryStream(a)
¤ With pbImage
¤ .Image = image.FromStrea m(b)
¤ .SizeMode =
¤ PictureBoxSizeM ode.CenterImage
¤ .BorderStyle = BorderStyle.Fix ed3D
¤ End With
¤ Catch exp As Exception
¤ MsgBox(exp.Mess age)
¤ End Try
¤ Catch exp As System.InvalidC astException
¤ MsgBox(exp.Mess age)
¤ 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******@amerit ech.net
Microsoft MVP (Visual Basic)

Nov 20 '05 #8
On 5 Apr 2004 16:50:45 -0700, ab******@netsca pe.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******@amerit ech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #9
On 5 Apr 2004 16:50:45 -0700, ab******@netsca pe.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******@amerit ech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #10

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

Similar topics

4
8724
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 for the help..
1
2889
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 can display a invalid image try dim strConn as string strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.mappath
20
929
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 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
1
1441
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
8269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8203
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5576
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2630
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.