,有源程序更好?thank !!!!!

解决方案 »

  1.   

    注:写图片文件到数据库 
        Col为栏位名,ImgFile为要写到数据库的图片文件名,BockSize为每次写多少字节,缺省为每次写8K字节到数据库 
        Public Sub WriteDB(Col As ADODB.Field, ImgFile As String, Optional BlockSize As Long=8192) 
         Dim byteData() As Byte, FileLength As Long, NumBlocks As Integer 
         Dim LeftOver As Long, SourceFileNum As Integer, i As Integer 
         
         SourceFileNum = FreeFile 
         Open ImgFile For Binary As SourceFileNum 
         FileLength = LOF(SourceFileNum) 
         If FileLength > 50 Then 
         NumBlocks = FileLength \ BlockSize 
         LeftOver = FileLength Mod BlockSize 
         
         ReDim byteData(LeftOver) 
         Get SourceFileNum, , byteData() 
         Col.AppendChunk byteData() 
         ReDim byteData(BlockSize) 
         For i = 1 To NumBlocks 
         Get SourceFileNum, , byteData() 
         Col.AppendChunk byteData() 
         Next 
         End If 
         Close SourceFileNum 
        End Sub 
         
         
        ImgFile为从数据库读出数据写到磁盘的文件名,BlockSize为每次向文件写多少个字节,缺省为8K字节,当ReadDB=True,得到图片文件後,可以用LoadPicter(图片文件名)显示图片到PictureBox或Image框中. 
        Public Function ReadDB(Col As ADODB.Field, ImgFile As String,Optional BlockSize As Long=8192) As Boolean 
         Dim byteData() As Byte, NumBlocks As Integer 
         Dim LeftOver As Long, DestFileNum As Integer, i As Integer 
         Dim ColSize As Long 
         
         On Error GoTo ErrRead 
         ReadDB = False 
         
         'If Dir(ImgFile) <> "" Then Kill ImgFile 
         
         DestFileNum = FreeFile 
         Open ImgFile For Binary As #DestFileNum 
         
         ColSize = Col.ActualSize 
         NumBlocks = ColSize \ BlockSize 
         LeftOver = ColSize Mod BlockSize 
         
         ReDim byteData(LeftOver) 
         byteData() = Col.GetChunk(LeftOver) 
         Put DestFileNum, , byteData() 
         ReDim byteData(BlockSize) 
         For i = 1 To NumBlocks 
         byteData() = Col.GetChunk(BlockSize) 
         Put #DestFileNum, , byteData() 
         Next 
         If LOF(DestFileNum) > 200 Then ReadDB = True 
         Close #DestFileNum 
         Exit Function 
         
        ErrRead: 
         MsgBox "READ PICTURE ERR:" & Err.Number 
         ReadDB = False 
         Exit Function 
        End Function//如果ReadDB=False则写文件失败。 
        还有用此纯代码读取图片时,在代码调试中不会出现错误,在运行时如果快速浏览带有图片的记录时,会出现莫名其妙的程序死机.如上述代码,我都用了错误控制技术,但还是出现。 
        我用的是VB6.0 ADO方法 + SQL SERVER 7.0(都是英文版)C/S架构,如有能够解决此死机问题的,请在下面继续贴出。 
      

  2.   

    WORD文档也差不多都是当大文本处理吧
      

  3.   

    用ADO.stream保存BLOB数据(把word文件看做二进制数据)
      

  4.   

    dim diskfileas string
    dim filelength as long
    dim bytedata() as byte
    rs.open "select filedname from table"
    diskfile=word文件名(包含路径)
    open diskfile for binary access read as #1
    filelength=lof(10
    redim bytedata(filelength)
    get #1,,bytedata()
    rs.fileds(序号).appendchunk bytedata()
    close #1
      

  5.   

    '假设数据库中对应的表为tb1,
    '结构如:create tabel tb1(id int identity(1,1),WordValue image)
    '那么我就可以将word文档存入此表的WordValue字段Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim stm As ADODB.StreamPrivate Sub SaveDocToDB(cn As ADODB.Connection)
    On Error GoTo EH
        Set stm = New ADODB.Stream
        rs.Open "select WordValue from tbl", cn, adOpenKeyset, adLockOptimistic
        CommonDialog1.ShowOpen
        Text1.Text = CommonDialog1.FileName
        
        With stm
             .Type = adTypeBinary
             .Open
             .LoadFromFile CommonDialog1.FileName
        End With
        With rs
             .AddNew
             .Fields("wordValue") = stm.Read
             .Update
        End With
        rs.Close
        Set rs = Nothing
    Exit Sub
    EH: MsgBox Err.Description, vbInformation, "Error"
    End Sub
    Private Sub LoadDcFromDB(cn As ADODB.Connection)
    '读出
    On Error GoTo EH
        Dim strTemp As String
        Set stm = New ADODB.Stream
        strTemp = "c:\temp.doc" '临时文件,用来保存读出的文档
        rs.Open "select WordValue  from tbl where id=1", cn, , , adCmdText
        With stm
            .Type = adTypeBinary
            .Open
            .Write rs("WordValue")
            .SaveToFile strTemp, adSaveCreateOverWrite
            .Close
        End With
        Set stm = Nothing
        rs.Close
        Set rs = Nothing
    Exit Sub
    EH: MsgBox Err.Description, vbInformation, "Error"
    End Sub
      

  6.   

    作二进制文件处理时,列变量是什末?在从库中读出时,写在什末格式WORD能调用?
      

  7.   

    没看我的么??
    这里都说明了!!
    '假设数据库中对应的表为tb1,
    '结构如:create tabel tb1(id int identity(1,1),WordValue image)
    '那么我就可以将word文档存入此表的WordValue字段即将此字段类型设为image(或text\ntext) (sqlserver中)
      

  8.   

    存的时候用Appendchunk,取的时候用Getchunk,很方便的。类型image就可以啊。