精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● VB和Basic>>〓〓...多媒体相关...〓〓>>请教高手:关于 Image 控件,急!!!!

主题:请教高手:关于 Image 控件,急!!!!
发信人: long007()
整理人: fishy(2000-01-06 16:06:56), 站内信件
我的一个例子,你对照看看就知道了。
Const mLNG_CHUNK_SIZE = 1024 * 4


Public Function SaveFileToDB(FileName As String, FileType As String, K
eyValue As String, Optional Djrq As Date) As Boolean
    Dim strSQL As String
    Dim rsDocument As Recordset
    Dim strKeyField As String
    Dim strDocField As String
    Dim lngFileSize As Long
    Dim bytChunk() As Byte
    Dim intChunks As Integer
    Dim lngFragment As Long
    Dim i As Integer
    
    Select Case FileType
    Case "ZlzsZsda"
        strSQL = "select fxgcid,djrq,zsda from ZlzsDocs where fxgcid='
" & KeyValue & "'"
        strKeyField = "fxgcid"
        strDocField = "zsda"
    End Select
    
    On Error GoTo Err_OpenFile
    Open FileName For Binary Access Read As 1
    On Error GoTo 0
    lngFileSize = LOF(1)
    If lngFileSize = 0 Then
        Close
        MsgBox "文件内容为空", , App.Title
        SaveFileToDB = False
        Exit Function
    End If
    
    Set rsDocument = New Recordset
    rsDocument.Open strSQL, gcnDocsDB, adOpenKeyset, adLockOptimistic

    If rsDocument.RecordCount = 0 Then
        rsDocument.AddNew
        rsDocument.Fields(strKeyField) = KeyValue
    Else
        rsDocument.Fields(strDocField) = Null
    End If
    
    rsDocument.Fields("djrq") = Djrq
    
    intChunks = lngFileSize \ mLNG_CHUNK_SIZE
    lngFragment = lngFileSize Mod mLNG_CHUNK_SIZE
    ReDim bytChunk(lngFragment)
    Get 1, , bytChunk()
    rsDocument.Fields(strDocField).AppendChunk bytChunk()
    ReDim bytChunk(mLNG_CHUNK_SIZE)
    For i = 1 To intChunks
        Get 1, , bytChunk()
        rsDocument.Fields(strDocField).AppendChunk bytChunk()
    Next
    
    On Error GoTo Err_Update
    rsDocument.Update
    On Error GoTo 0
    rsDocument.Close
    Set rsDocument = Nothing
    
    Close
    SaveFileToDB = True
    Exit Function
    
Err_OpenFile:
    MsgBox Err.Description, , App.Title
    SaveFileToDB = False
    Exit Function

Err_Update:
    rsDocument.CancelUpdate
    rsDocument.Close
    Set rsDocument = Nothing
    Close
    MsgBox Err.Description, , App.Title
    SaveFileToDB = False
    Exit Function

End Function


【 在 ary (阿强驸马) 的大作中提到: 】
: 本人的 VB 的 Image 控件已经有一个图片(该图片不是由文件读入),
: 我希望能够获得该图片的二进制数据,并把这些二进制数据保存入数据库。

: 问题是如何获得这些二进制数据?
:    .......


--
我是一只只会爬的小蚂蚁,却想敲开天堂之门!

※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.103.111.48]

[关闭][返回]