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

Problem with write binary data to OLE field in Access

Hi~

I would like to save images in OLE field in Microsoft Access. It writes
the binary data which read from an JPEG/BMP file.
But seems I meet an encoding problem.
The following code demos that.
Any sugguestion?

---------------------------------------------------------------------------
import win32com.client as wc

conn = wc.Dispatch(r'ADODB.Connection')
recordset = wc.Dispatch(r'ADODB.RecordSet')

dsn = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source="test.mdb";'
conn.Open(dsn)
print conn

k = recordset.Open('[tblImageDataTypes]', conn, 1, 3)

#recordset.AddNew()
#recordset.Fields('Field3_GENERAL').AppendChunk(op en('tt.jpg', 'rb').read())
#recordset.Update()
#print ">>Actual Size: ", recordset.Fields('Field3_GENERAL').ActualSize

recordset.MoveFirst()
kk = recordset.Fields('Field3_GENERAL').GetChunk(
recordset.Fields('Field3_GENERAL').ActualSize)
print len(str(kk).decode('utf-16'))
print len(open('tt.jpg', 'rb').read())

recordset.Close
conn.Close()
###############################
One of the results:
the length of original file is : 2598
the actual size of the field is: 3658
the length decode from the chunk is: 1829

I try to write some text files into the filed and read it out, it is OK.
Windows XP sp2; Python 2.4.4; Pywin32 210; Microsoft Access 2002
---------------------------------------------------------------------------------------
Regards,
lialie
Mar 26 '08 #1
0 1524

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

Similar topics

3
by: kee | last post by:
Hi All, I am trying to write binary data to a file, which is bmp image: Open "d:\temp\test001.bmp" For Binary Access Write As #1 Put #1, 1, strImage Close #1 *** strImage contains binary...
8
by: Brandon McCombs | last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm trying here. I have a C++ book by Deitel and Deitel that says I can use fstream File("data.dat", ios::in | ios::out |...
9
by: philip | last post by:
If I execute that : Dim Temp as string = "This is a text" Dim sw As StreamWriter Dim fullFileName as string = "c:\text.txt" sw = New StreamWriter(fullFilename) sw.Write(temp) sw.Close() ...
5
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
8
by: Mark | last post by:
Hello. I am attempting to write binary data from a file to an OLE Object field, and then write the file back out from the database. I am reading and writing the files in binary mode, and using...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
5
by: pnjones | last post by:
I am getting the write conflicit when 2 users access the same record the first one to save is allowed but the second user gets the message Write conflicit with the save option greyed out. I have...
3
by: tracethepath | last post by:
hello everybody... i am trying to make a project on binary files and that needs a function to modify data in a binary file. I have made the following class. class example { public: ...
5
by: zehra.mb | last post by:
Hi, I had written application for storing employee data in binary file and reading those data from binary file and display it in C language. But I face some issue with writing data to binary file....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.