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 13 3700
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
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
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
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
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
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
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
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
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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.
...
|
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...
|
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.
|
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...
|
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...
|
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...
|
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...
|
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">...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |