错误产生再.UPDATE时,换作其他字段(非BLOB),不产生任何错误。

解决方案 »

  1.   

    同情你!
    丢掉AppendChunk和GetChunk吧!
    其实可以这样的,以SQL Server2000为例!
    ado2.6以上都有了Stream对象了!
    用ado的stream对象,使用方便而且是发展趋势。Private Sub DisplayBLOBGrid(cn As ADODB.Connection)
        
        Dim rs As New ADODB.Recordset
        Dim fld As ADODB.Field
        
        Dim stm As New ADODB.Stream
        Dim sFileName As String
        
        sFileName = App.Path & "\tempBLOB.bmp"
        
        MousePointer = vbHourglass
        
        rs.Open "Select pub_id, logo From pub_info", cn, , , adCmdText
        
        ' Setup the hflxResults
        hflxResults.Redraw = False
        hflxResults.Clear
        hflxResults.Cols = rs.Fields.Count
        hflxResults.Rows = 1
        hflxResults.Row = 0
        hflxResults.Col = 0
        'Size the hflxResults columns bigger thatn normal
        hflxResults.ColWidth(0) = TextWidth(String(rs.Fields(0).ActualSize + 4, "a"))
        hflxResults.ColWidth(1) = TextWidth(String(200, "a"))
        hflxResults.RowHeightMin = hflxResults.RowHeight(0) * 3
                
        'Setup the headings
         For Each fld In rs.Fields
             hflxResults.Text = fld.Name
             If hflxResults.Col < rs.Fields.Count - 1 Then
                hflxResults.Col = hflxResults.Col + 1
             End If
        Next fld    ' Move through each row in the record set
        Do Until rs.EOF
            
            ' Set the position in the hflxResults
            hflxResults.Rows = hflxResults.Rows + 1
            hflxResults.Row = hflxResults.Rows - 1
            hflxResults.Col = 0
            
            'Loop through all fields
            For Each fld In rs.Fields
                
                If fld.Type = adLongVarBinary Then
                    
                    With stm
                        .Type = adTypeBinary
                        .Open
                        .Write fld.Value
                    End With
                
                    'Store the image into a temp bitmap file
                    stm.SaveToFile sFileName, adSaveCreateOverWrite
                    stm.Close
                    hflxResults.CellPictureAlignment = flexAlignLeftCenter
                    'Load the temporary bitmap into the hflxResults
                    Set hflxResults.CellPicture = LoadPicture(sFileName)
                Else
                    'Treat the column as regular data
                    hflxResults.Text = fld.Value
                End If
                If hflxResults.Col < rs.Fields.Count - 1 Then
                    hflxResults.Col = hflxResults.Col + 1
                End If
            Next fld
        
            rs.MoveNext
        Loop
        
        ' If there was no data returned set the grid to show 2 rows
        If hflxResults.Rows < 2 Then
            hflxResults.Rows = 2
        End If
        
        ' Set the fixed rows and redraw the grid
        hflxResults.FixedRows = 1
        hflxResults.Redraw = True
        
        'Close up all the ADO objects
        rs.Close
        Set rs = Nothing
        Set stm = Nothing
        
        MousePointer = vbDefaultEnd Sub