473,756 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Pi cture") = CType(pbDog.Ima ge, Bitmap)

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

Thanks for the information.

Brad
Nov 20 '05 #1
6 1413
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*******@sbcg lobal.net> wrote in message
news:Om******** *****@TK2MSFTNG P10.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("Pi cture") = CType(pbDog.Ima ge, 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*******@sbcg lobal.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("Pi cture") = CType(pbDog.Ima ge, Bitmap)

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


\\\
Dim b As New Bitmap("C:\WIND OWS\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.Begi n)
ms.Read(abyt, 0, ms.Length)

' Byte array is filled.

Dim mx As New MemoryStream(ab yt)
Me.BackgroundIm age = Bitmap.FromStre am(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:\WIND OWS\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:\WIND OWS\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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
'Reading a picture and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(f o.FileName, _
IO.FileMode.Ope n)
Dim br As New IO.BinaryReader (fs)
abyt = br.ReadBytes(CI nt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream (abyt)
Me.PictureBox1. Image = Image.FromStrea m(ms)
End If
End Sub

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

Private Sub Button3_Click(B yVal sender As System.Object, ByVal _
e As System.EventArg s) Handles Button3.Click
'writing a bytearray to a dataset
Dim ds As New DataSet
ds.Tables.Add(N ew DataTable("Phot o"))
ds.Tables(0).Co lumns.Add(New DataColumn("Sam ple"))
ds.Tables(0).Co lumns(0).DataTy pe =
System.Type.Get Type("System.By te[]")
ds.Tables(0).Ro ws.Add(ds.Table s(0).NewRow)
ds.Tables(0).Ro ws(0)(0) = abyt
Dim sf As New SaveFileDialog
If sf.ShowDialog = DialogResult.OK Then
ds.WriteXml(sf. FileName, XmlWriteMode.Wr iteSchema)
End If
End Sub

Private Sub Button4_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button4.Click
'reading a picture from a dataset
Dim ds As New DataSet
If fo.ShowDialog = DialogResult.OK Then
ds.ReadXml(fo.F ileName)
End If
abyt = CType(ds.Tables (0).Rows(0)(0), Byte())
Dim ms As New IO.MemoryStream (abyt)
Me.PictureBox1. Image = Image.FromStrea m(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**********@p lanet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP09.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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
'Reading a picture and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(f o.FileName, _
IO.FileMode.Ope n)
Dim br As New IO.BinaryReader (fs)
abyt = br.ReadBytes(CI nt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream (abyt)
Me.PictureBox1. Image = Image.FromStrea m(ms)
End If
End Sub

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

Private Sub Button3_Click(B yVal sender As System.Object, ByVal _
e As System.EventArg s) Handles Button3.Click
'writing a bytearray to a dataset
Dim ds As New DataSet
ds.Tables.Add(N ew DataTable("Phot o"))
ds.Tables(0).Co lumns.Add(New DataColumn("Sam ple"))
ds.Tables(0).Co lumns(0).DataTy pe =
System.Type.Get Type("System.By te[]")
ds.Tables(0).Ro ws.Add(ds.Table s(0).NewRow)
ds.Tables(0).Ro ws(0)(0) = abyt
Dim sf As New SaveFileDialog
If sf.ShowDialog = DialogResult.OK Then
ds.WriteXml(sf. FileName, XmlWriteMode.Wr iteSchema)
End If
End Sub

Private Sub Button4_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button4.Click
'reading a picture from a dataset
Dim ds As New DataSet
If fo.ShowDialog = DialogResult.OK Then
ds.ReadXml(fo.F ileName)
End If
abyt = CType(ds.Tables (0).Rows(0)(0), Byte())
Dim ms As New IO.MemoryStream (abyt)
Me.PictureBox1. Image = Image.FromStrea m(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
1457
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 right eccept it shows them as thumbnails and opens in a new windows despite the target setting. any ideas?? thanks harold
4
15071
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 can call the pic by url(project/pic/a.jpg) However, its very inconveninet when I change the folder name eg from project to project10.
1
1605
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 to upload their own pics via ASPupload so that they can be used on their site. I use a very simple form with a INPUT file box to allow them to browse, select and upload the picture. I then use ASPupload to save the file, get the file params and...
2
1691
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 the txtFilename text box. Can access do this?
4
1381
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 properties like image, collections such as tabpage's cannot done with this method. Anybody can help me on how to save and later restore the complex properties?
4
3302
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 errors. After reading the ole object from db, I saved it to C: as file1.bmp and displayed on the web. But it can not be displayed. After I manually sent the file to wordpad, it shows
4
6724
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 code ?? thank you Pedro Leite From Portugal ------------------------------------
4
1890
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 have to right click on every link and do a save picture as...? I can't link directly to the pics from our site because our site is https and the site the pics are on are http so the user gets the security warning box every time a pic loads. ...
0
1344
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 website appears in my browser with pics so that tells me that data is being retrieved from the db file. Not sure what is going on. I receive this error when saving a new website. This one in particular is a starter kit for the Business website. I...
0
9275
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
10040
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9713
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
8713
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5142
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...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3806
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
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.