473,466 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Extracting Image from database & displaying in picture box

PS
I want to display the image from database to picture box through ado.net and vb.net

I have some images present in a sql server 2000 table stored under 'image' datatype. I want to extract and display them in a picture box present in a vb.net form

I appreciate any help on this

Thanks
PS
Jul 21 '05 #1
13 3705
http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
"PS" <an*******@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
I want to display the image from database to picture box through ado.net and vb.net?
I have some images present in a sql server 2000 table stored under 'image' datatype. I want to extract and display them in a picture box present in a
vb.net form.
I appreciate any help on this.

Thanks,
PS

Jul 21 '05 #2
Hi PS,

Reading it from a file, writing it to a file, putting it in the database,
reading it to the database,

Used is an XML file just to make it easy as sample.

I hope this helps a little bit.

Cor

Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Reading a picture and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a dataset
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType =
System.Type.GetType("System.Byte[]")
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyt
Dim sf As New SaveFileDialog
If sf.ShowDialog = DialogResult.OK Then
ds.WriteXml(sf.FileName, XmlWriteMode.WriteSchema)
End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a dataset
Dim ds As New DataSet
If fo.ShowDialog = DialogResult.OK Then
ds.ReadXml(fo.FileName)
End If
abyt = CType(ds.Tables(0).Rows(0)(0), Byte())
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub

Jul 21 '05 #3
Hi Bill,

I do not know your relation to the maker of that sample, however in my
opinion uses it very much more code and resources (disk) than is needed.

I know that I have to complete that website I started with, I started with
it however I am in doubt if it has real value to complete it there is
already so much. Herfried did look to it, however that is not someone to be
a judge, will you have a look for me to it?

(I have still your email adres, to send you the link).

Cor
Jul 21 '05 #4
PS
Hi Co

I am getting an error "Invalid Parameter Used" at
Me.PictureBox1.Image = Image.FromStream(ms

I appreciate your hel

Thanks
P

----- Cor Ligthert wrote: ----

Hi PS

Reading it from a file, writing it to a file, putting it in the database
reading it to the database

Used is an XML file just to make it easy as sample

I hope this helps a little bit

Co

Private abyt() As Byt
Private fo As New OpenFileDialo
Private sf As New SaveFileDialo
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e A
System.EventArgs) Handles Button1.Clic
'Reading a picture and put it in a bytearra
If fo.ShowDialog = DialogResult.OK The
Dim fs As New IO.FileStream(fo.FileName,
IO.FileMode.Open
Dim br As New IO.BinaryReader(fs
abyt = br.ReadBytes(CInt(fs.Length)
br.Close(
'just to show the sample without a fileread erro
Dim ms As New IO.MemoryStream(abyt
Me.PictureBox1.Image = Image.FromStream(ms
End I
End Su

Private Sub Button2_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button2.Clic
'writing a picture from a bytearra
If sf.ShowDialog = DialogResult.OK The
Dim fs As New IO.FileStream(sf.FileName,
IO.FileMode.CreateNew
Dim bw As New IO.BinaryWriter(fs
bw.Write(abyt
bw.Close(
End I
End Su

Private Sub Button3_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button3.Clic
'writing a bytearray to a datase
Dim ds As New DataSe
ds.Tables.Add(New DataTable("Photo")
ds.Tables(0).Columns.Add(New DataColumn("Sample")
ds.Tables(0).Columns(0).DataType
System.Type.GetType("System.Byte[]"
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow
ds.Tables(0).Rows(0)(0) = aby
Dim sf As New SaveFileDialo
If sf.ShowDialog = DialogResult.OK The
ds.WriteXml(sf.FileName, XmlWriteMode.WriteSchema
End I
End Su

Private Sub Button4_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button4.Clic
'reading a picture from a datase
Dim ds As New DataSe
If fo.ShowDialog = DialogResult.OK The
ds.ReadXml(fo.FileName
End I
abyt = CType(ds.Tables(0).Rows(0)(0), Byte()
Dim ms As New IO.MemoryStream(abyt
Me.PictureBox1.Image = Image.FromStream(ms
End Su


Jul 21 '05 #5
Hi I should document it better once I think.

I tested it again and it works fine for me, however, you should first with
button 1 read a file from disk, and than if you want write that to a dataset
on disk and save the dataset and than you can read the dataset and than the
image is displayed from. Button 1, 3 and 4.

I tell this because this sentence you showed is two times in the sample,
ones with button 1 and once with button 4 so which one is it.

:-)

Cor
Jul 21 '05 #6
I don't have any relation with Mahesh other than a professional admiration
of his work. I'd love to see what you have instead but I don't think in the
overall context of what he's doing that it's wasteful. I did a review of
two of his books including the GDI+ title
http://www.c-sharpcorner.com/Store/B...21-16077-0.asp which that
example is from. I think it's a great book.

As far as being wasteful, I don't think storing blobs in a Database is ever
going to win any efficiency awards. All of the serialization and
deserialization and the like is never going to be as easy as opening a file
on a network share or local drive. However if your requirement is that you
have to do this, then it's as good of a method as any.

However I always love to see other ideas so by all means, zing me the code
(dotnetguru At Comcast Dot Net)

Thanks again,

Bill
--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Hi Bill,

I do not know your relation to the maker of that sample, however in my
opinion uses it very much more code and resources (disk) than is needed.

I know that I have to complete that website I started with, I started with
it however I am in doubt if it has real value to complete it there is
already so much. Herfried did look to it, however that is not someone to be a judge, will you have a look for me to it?

(I have still your email adres, to send you the link).

Cor

Jul 21 '05 #7
Hi PS,

This should be all you need
Where the zeros are of course the indexes.
And do not close the memorystream.

When it is not working show me your code than I look to it tomorrow because
it is evening here again.

Dim abyt() as byte = DirectCast(ds.Tables(0).Rows(0)(0), Byte())
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)

Cor

Jul 21 '05 #8
Hi Ps,

An easy one I think,
Dim cmd As New SqlCommand("Select Signature From imagetest where name='David'", cn)
Dim abyt() As Byte =

DirectCast(ds.Tables("imagetest").Rows(0)("signatu re"), Byte())

The field name is case sensetive luckily you wrote no * in the select so I
could see this.

Signature signature

Probably that is the error?

Cor
Jul 21 '05 #9
Hi PS,

There are, however this one should work, the message parameters has in my
opinion nothing to do with the picture on what row do you get it?

Cor
Though I changed 'signature' to 'Signature', the same error 'Invalid parameter used' still comes.
Is there another way to display an image from database to picture box?

Thanks of all your help,
PS

Jul 21 '05 #10
PS
Hi Cor

I have signatures drawn on the form using xy coordinates and stored in 'image' datatype of sql server 2000 table
I want to extract them from database table and draw them on a vb.net form as X & Y points/coords and make an image of signature again

Is there a way to do this

Your help/ suggestions is greatly appreciated

Thanks
P

Jul 21 '05 #11
Hi PS,

There are two persons active in the newsgroups from which I think they can
can give you an answer on your question they are both active in different
newsgroups.

microsoft.public.dotnet.languages.vb
microsoft.public.dotnet.drawings

Are you sure it are not OLE Access 97 images or like that than you have to
make some little changes in the code I did show you.
I thought that I had it in VB.net however I cannot find it anymore, this is
it in C#, when you can not convert it tell me, than I do it and than I have
it in VB.net as well again.

http://groups.google.com/groups?selm...7b9e%404ax.com

I hope this helps?

Cor
Jul 21 '05 #12
PS
Thanks Cor

I am sure they are not OLE Access 97 images. All I have to do is extract the signatures from table and draw on form or picturebox at xy coords and get the image signature

Anyways, Thanks for your immense help and very quick and prompt replies

Rgds
P
----- Cor Ligthert wrote: ----

Hi PS

There are two persons active in the newsgroups from which I think they ca
can give you an answer on your question they are both active in differen
newsgroups

microsoft.public.dotnet.languages.v
microsoft.public.dotnet.drawing

Are you sure it are not OLE Access 97 images or like that than you have t
make some little changes in the code I did show you
I thought that I had it in VB.net however I cannot find it anymore, this i
it in C#, when you can not convert it tell me, than I do it and than I hav
it in VB.net as well again

http://groups.google.com/groups?selm...g7b9e%404ax.co

I hope this helps

Co

Jul 21 '05 #13
Hi there

Even I am having EXECTLY the same problem.... I have tried .gifs and even .jpg's
and I still get the Invalid Parameters error.

Any progress on this issue?

Thanks!
Steve

"PS" wrote:
Thanks Cor,

I am sure they are not OLE Access 97 images. All I have to do is extract the signatures from table and draw on form or picturebox at xy coords and get the image signature.

Anyways, Thanks for your immense help and very quick and prompt replies.

Rgds,
PS
----- Cor Ligthert wrote: -----

Hi PS,

There are two persons active in the newsgroups from which I think they can
can give you an answer on your question they are both active in different
newsgroups.

microsoft.public.dotnet.languages.vb
microsoft.public.dotnet.drawings

Are you sure it are not OLE Access 97 images or like that than you have to
make some little changes in the code I did show you.
I thought that I had it in VB.net however I cannot find it anymore, this is
it in C#, when you can not convert it tell me, than I do it and than I have
it in VB.net as well again.

http://groups.google.com/groups?selm...7b9e%404ax.com

I hope this helps?

Cor

Jul 21 '05 #14

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

Similar topics

1
by: PS | last post by:
I want to extract an image from sqlserver 2000 table and display it in picture box in vb.net form using ado.net and vb.net The image in the sql server 2000 table is stored in 'image' datatype. ...
1
by: Rob Parker | last post by:
I posted this with a different subject line (in two posts - I added additional info in the second) in this newsgroup a few days ago, but haven't had a single response. Hopefully, that was because...
2
by: Andrew | last post by:
Hi, How do I display a single image in a repeater control ? I only have 1 picture to display for ONE of my records. TIA. Andrew.
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
13
by: PS | last post by:
I want to display the image from database to picture box through ado.net and vb.net I have some images present in a sql server 2000 table stored under 'image' datatype. I want to extract and...
3
by: velu | last post by:
Asp.Net 2 I am trying to display Image from Northwind Database. I ran a queary "SELECT CategoryID, CategoryName, Description, Picture FROM Categories" but the Dataview displayes all the fields...
1
by: rascalking | last post by:
Hello, So I've read many forums that explained how to get an image out of SQL Server database and display it. I used an alternate .aspx page to retrieve the image and write it back as binary...
2
by: amritranjan | last post by:
This is my Jsp code for image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title> </head> <body bgproperties="fixed" bgcolor="#CCFFFF">...
1
by: sravani1 | last post by:
This code runs like when i submit the form it takes the image and displayed and top of the image a map will displayed. But actually i want that when i give the image it checks the location in the map...
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
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.