???

解决方案 »

  1.   

    const blocksize = 8192
    public sub savetodb(byref fld as adodb.field, diskfile as string)
      dim bytedata() as byte '定义数据块数组
      dim numblocks as long  '定义数据块个数
      dim filelength as long '标识文件长度
      dim leftover as long '定义剩余字节长度
      dim sourcefile as long '定义自由文件号
      dim i as long   '定义循环变量
      sourcefile = freefile '提供一个尚未使用的文件号
      open diskfile for binary access read as sourcefile '打开文件
      filelength = lof(sourcefile) '得到文件长度
      if filelength = 0 then '判断文件是否存在
    close sourcefile
    msgbox diskfile & "无 内 容 或 不 存 在 !"
      else
    numblocks = filelength \ blocksize '得到数据块的个数
    leftover = filelength mod blocksize '得到剩余字节数
    fld.value = null
    redim bytedata(blocksize) '重新定义数据块的大小
    for i = 1 to numblocks
        get sourcefile, , bytedata() '读到内存块中
        fld.appendchunk bytedata()   '写入fld
    next i
    redim bytedata(leftover) '重新定义数据块的大小
    get sourcefile, , bytedata() '读到内存块中
    fld.appendchunk bytedata() '写入fld
    close sourcefile '关闭源文件
      end if
    end sub
    public sub readfromdb(byref fld as adodb.field, diskfile as string)
      dim bytedata() as byte '定义数据块数组
      dim numblocks as long  '定义数据块个数
      dim filelength as long '标识文件长度
      dim leftover as long '定义剩余字节长度
      dim loffset as long
      dim sourcefile as long '定义自由文件号
      dim i as long '定义循环变量
      sourcefile = freefile '提供一个尚未使用的文件号
      open diskfile for binary access write as sourcefile '打开文件
      filelength = fld.actualsize  '得到字段的实际长度
      if filelength = 0 then '判断文件是否存在

    close sourcefile
    ' msgbox diskfile & "无 内 容 或 不 存 在 !"
    exit sub
      else
    numblocks = filelength \ blocksize '得到数据块的个数
    leftover = filelength mod blocksize '得到剩余字节数
    'fld.value = null
    redim bytedata(leftover) '重新定义数据块的大小
    bytedata() = fld.getchunk(leftover)
    put sourcefile, , bytedata()
    loffset = leftover
    for i = 1 to numblocks
        redim bytedata(blocksize) '重新定义数据块的大小
        bytedata() = fld.getchunk(blocksize) '从数据库中读出一数据块到内存中
        put sourcefile, , bytedata() '从内存块写入文件中
        loffset = loffset + blocksize
        txtbytecount = loffset
    next i
    close sourcefile '关闭源文件
      end if
      

  2.   

    参考vb中如何保存图片到 sql server中,又如何读取出来??