类型:转载 责任编辑:asp 日期:2007/03/01
在access2000中有一个test表,其字段名称:ole_word,数据类型是ole对象。我现在要在vb6中把ole容器里编辑好的word文件保存到该字段中,请问我在ole容器中编辑完数据如何保存?急待高手帮忙!
还有如何使用ado直接读取该字段的内容到vb6的ole容器中。最好有源码.
推荐阅读
:
数据库字段:wjmc 文件名,wjsx 文件的扩展名。wjnr 文件的内容为二进制。(若access数据库为“ole对象”,sql server为“image”)
该程序可以操作所有的文件类型。
dim wenjian as string
dim rd as byte
dim size as long
const mysize = 1048576
dim wenjiann() as byte
dim rs as new adodb.recordset
rs.open "select * from wj", cn, 1, 3
rs.addnew
rs!wjmc = mid(name, 1, instr(name, ".") - 1)
rs!wjsx = mid(name, instr(name, ".") + 1)
‘name为文件的名称加扩展名
open filename for binary access read as #1
size = lof(1)
do while size - mysize >= 0
redim wenjiann(mysize) as byte
get #1, , wenjiann
rs!wjnr.appendchunk wenjiann
size = size - mysize
loop
if size > 0 then
redim wenjiann(size) as byte
get #1, , wenjiann
rs!wjnr.appendchunk wenjiann
end if
close #1
rs.update
set rs = nothing
最好把整个word文档保存到数据库,这样就不会丢失wrod中的格式及所有其它的一些内容。
完整的代码如下:如果是用sql那么保存文件的字段类型应该是binary。如果是用access,那么保存文件的字段应该用ole对象,在表中显示为长二进制数据。
将任何文件从数据库中下载到本地:
public function loadfile(byval col as adodb.field, byval filename as string) as boolean 获得binary数据
on error goto myerr:
dim arrbytes() as byte
dim freefilenumber as integer
lngsize = col.actualsize
arrbytes = col.getchunk(lngsize)
freefilenumber = freefile
open filename for binary access write as #freefilenumber
put #freefilenumber, , arrbytes
close #freefilenumber
loadfile = true
myerr:
if err.number <> 0 then
loadfile = false
err.clear
end if
end function
将文件从本地上传到数据库中
public function uploadfile(byval filename, byval col as adodb.field) as boolean
on error goto myerr:
dim arrbytes() as byte
dim freefilenumber as integer
freefilenumber = freefile
open filename for binary as #freefilenumber
n = lof(freefilenumber)
redim arrbytes(1 to n) as byte
get #freefilenumber, , arrbytes
close #freefilenumber
col.appendchunk (arrbytes)
uploadfile = true
myerr:
if err.number <> 0 then
uploadfile = false
err.clear
end if
end function
with the methods and properties of a stream object, you can do the following:
open a stream object from a record or url with the open method.
close a stream with the close method.
input bytes or text to a stream with the write and writetext methods.
read bytes from the stream with the read and readtext methods.
write any stream data still in the ado buffer to the underlying object with the flush method.
copy the contents of a stream to another stream with the copyto method.
control how lines are read from the source file with the skipline method and the lineseparator property.
determine the end of stream position with the eos property and seteos method.
save and restore data in files with the savetofile and loadfromfile methods.
specify the character set used for storing the stream with the charset property.
halt an asynchronous stream operation with the cancel method.
determine the number of bytes in a stream with the size property.
control the current position within a stream with the position property.
determine the type of data in a stream with the type property.
determine the current state of the stream (closed, open, or executing) with the state property.
specify the access mode for the stream with the mode property.
data控件可以连接access 2000数据库
你可以下载微软的mdac_typ或vb6的sp5
我看了你的帖子,做了一个程序,连接的就是access 2000数据库
随编辑,word文件随保存