标题:求助:为什么blob字段插入二进制文件,总显示null
只看楼主
lpzgzjh
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-8-8
 问题点数:0 回复次数:0 
求助:为什么blob字段插入二进制文件,总显示null
Private Sub FileToOLEfield(sFilename As String, OLEField As ADODB.Field)
    Dim FileNumber As Integer
    Dim FileBuffer() As Byte
    Dim FileSize As Long
    Dim ChunkSize As Long     '块大小
    Dim Flag As Integer
    On Error Resume Next
    ChunkSize = 32768
    FileNumber = FreeFile
    Flag = False
   
    Open sFilename For Binary As FileNumber
    FileSize = LOF(FileNumber)
    If FileSize > 0 Then
        Do Until Flag = True
            If (FileSize - Seek(FileNumber)) < ChunkSize Then
                ChunkSize = (FileSize - Seek(FileNumber) + 1)
                Flag = True
            End If
           
            ReDim FileBuffer(ChunkSize) As Byte
           
            Get #FileNumber, , FileBuffer
           
            OLEField.AppendChunk FileBuffer
        Loop
    End If
   
    Close #FileNumber
   
End Sub

Private Sub Command1_Click()
   
  CommonDialog1.DialogTitle = "图片资料"
  CommonDialog1.Filter = "图片文件(*.JPG;*.bmp;*.gif)|*.JPG;*.bmp;*.gif|所有文件(*.*)|*.*"
  CommonDialog1.Action = 1
  Image1.Picture = LoadPicture(CommonDialog1.FileName)

    Dim DcnNWind     As New ADODB.Connection
    Dim rs     As ADODB.Recordset
    Set rs = New ADODB.Recordset
    db_host = "192.168.100.232"
    connstr = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=" + db_host + ";DATABASE=" + "cp" + _
                    ";UID=" + "sp" + ";PWD=" + "" + ";OPTION=3;stmt=SET NAMES GBK"
   DcnNWind.Open connstr
        rs.Open "select * from images ", DcnNWind, adOpenKeyset, adLockPessimistic
       rs.AddNew
            FileToOLEfield CommonDialog1.FileName, rs.Fields("pic")
            rs.Update
            rs.Close
            SaveResourceFile = True
      
End Sub
搜索更多相关主题的帖子: blob 二进制 字段 null 文件 
2009-08-08 14:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-282026-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.142964 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved