473,396 Members | 1,933 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,396 software developers and data experts.

Saving pics in Access

I am using a small Access database as the back end of a VB .NET program. I
am not a newbie to Access, but I have never had the need to store pictures
until now. I have a field in a Master table named "Picture" and I have set
the Date Type as OLE Object. I know that this might be the wrong newsgroup
to post this to, but I was wondering if this is the correct data type to
handle pictures.

I use the following to store the pic in the datarow:
dogRow.Item("Picture") = CType(pbDog.Image, Bitmap)

The error message I am getting is this: Object must inplement IConvertible

Thanks for the information.

Brad
Nov 20 '05 #1
6 1393
Hi Brad:

That's not going to work b/c you need to read it in as a stream.
http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp

HTH,

Bill
www.devbuzz.com
www.knowdotnet.com

"Brad Allison" <tr*******@sbcglobal.net> wrote in message
news:Om*************@TK2MSFTNGP10.phx.gbl...
I am using a small Access database as the back end of a VB .NET program. I am not a newbie to Access, but I have never had the need to store pictures
until now. I have a field in a Master table named "Picture" and I have set the Date Type as OLE Object. I know that this might be the wrong newsgroup to post this to, but I was wondering if this is the correct data type to
handle pictures.

I use the following to store the pic in the datarow:
dogRow.Item("Picture") = CType(pbDog.Image, Bitmap)

The error message I am getting is this: Object must inplement IConvertible
Thanks for the information.

Brad

Nov 20 '05 #2
* "Brad Allison" <tr*******@sbcglobal.net> scripsit:
I am using a small Access database as the back end of a VB .NET program. I
am not a newbie to Access, but I have never had the need to store pictures
until now. I have a field in a Master table named "Picture" and I have set
the Date Type as OLE Object. I know that this might be the wrong newsgroup
to post this to, but I was wondering if this is the correct data type to
handle pictures.

I use the following to store the pic in the datarow:
dogRow.Item("Picture") = CType(pbDog.Image, Bitmap)

The error message I am getting is this: Object must inplement IConvertible


\\\
Dim b As New Bitmap("C:\WINDOWS\Angler.bmp")
Dim ms As New MemoryStream
b.Save(ms, ImageFormat.Bmp)
Dim abyt(ms.Length - 1) As Byte

' Let's assume that 'abyt' is a byte array containing bitmap data read
' from the db after filling it...

ms.Seek(0, SeekOrigin.Begin)
ms.Read(abyt, 0, ms.Length)

' Byte array is filled.

Dim mx As New MemoryStream(abyt)
Me.BackgroundImage = Bitmap.FromStream(mx)

' Keep the memory stream upen until you don't need the image any more.
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
\\\
Dim b As New Bitmap("C:\WINDOWS\Angler.bmp")


Herfried,

Does the picture have to be a bitmap to do this?

Nov 20 '05 #4
scorpion53061 schrieb:
\\\
Dim b As New Bitmap("C:\WINDOWS\Angler.bmp")


Does the picture have to be a bitmap to do this?


No, not necessarily. It will work with JPEG, GIF, PNG, and maybe TIFF, too.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
Hi Bard,

Every thing you want to know about it reading/writting, used is a xml
dataset.

In this complete example is everything skipped that is not really needed.
(Which are often in others samples about this, however not the Herfried one)

I hope this helps?

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
Nov 20 '05 #6
Thanks for the responses. I will try this code when I get home tonight.

Brad

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi Bard,

Every thing you want to know about it reading/writting, used is a xml
dataset.

In this complete example is everything skipped that is not really needed.
(Which are often in others samples about this, however not the Herfried one)
I hope this helps?

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

Nov 20 '05 #7

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

Similar topics

2
by: harold | last post by:
hi guys, i going mad trying to create a page that has the contents of a folder down one frame (pics, in list form) and when i click one of them it opens in the opposing frame. i have it just about...
4
by: Jorntk | last post by:
I have css in a folder name css. so how can this .css file read a pics file from another folder eg, pics/a.jpg. Both css folder and pics folder are located in a folder named project. I know i...
1
by: Laphan | last post by:
First of all, my apologies for the xpost. I realise the netiqute, but this query seems to cross the boundaries of both these groups. Basically I have created a small ASP site that allows a user...
2
by: Josh | last post by:
Currently we open a form and manualy place the pic in each new record. I need someway for to give Access a folder and then have it import each pic it finds in the folder and place the file name in...
4
by: Özden Irmak | last post by:
Hello, I'm trying to save some properties of some windows controls into a XML File. Most of the properties work when I save them as String (TypeConverter.ConvertToString). But some complex...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
4
by: Jake G | last post by:
Hi, I wrote a script to generate links to some pictures that I need to regularly update our site with. Is there a way to write a script that just saves the pics to a directory on my pc so I dont...
0
by: Tony K | last post by:
ERROR MESSAGE RECEIVED WHEN SAVING. "The operation could not be completed. No such interface supported." Dell Inspirion E1705, 1GB RAM, Windows Vista Ultimate I can start debugging and the...
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
0
BarryA
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...
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:
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...
0
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...
0
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...

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.