在Access2000中有一个Test表,其字段名称:Ole_Word,数据类型是OLE对象。我现在要在VB6中把OLE容器里编辑好的Word文件保存到该字段中,请问我在OLE容器中编辑完数据如何保存?急待高手帮忙!还有如何使用ADO直接读取该字段的内容到VB6的OLE容器中。最好有源码.
  

解决方案 »

  1.   

    : 
        数据库字段: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 
         
         
      

  2.   

    最好把整个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 
      

  3.   

    谢谢各位,从数据库中读取和写入OLE字段的方法,我已经解决。我的问题是:
    我用VB中OLE容器控件嵌入Word文件,然后编辑,编辑完成后,我要如何保存在OLE容器中修改的Word的文件?
      

  4.   

    to  sxs69()
    Data控件不能连接Access 2000数据库。
      

  5.   

    其实我觉得用stream要比AppendChunk 要好。简单好用,是微软用来代替appendchunk的你可以查一下MSDN,只有几个方法调用,挺简单的,代码行数也会减少好多:)
      

  6.   

    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. 
      

  7.   

    Data控件可以连接Access 2000数据库
    你可以下载微软的mdac_typ或VB6的SP5
    我看了你的帖子,做了一个程序,连接的就是Access 2000数据库
    随编辑,WORD文件随保存