2013-01-24 23 views
0
'code to load picture into database table 
Private Function GetPic() 
    Dim filelen As Long 
    Dim numlock As Integer 
    Dim leftover As Long 
    Const blocksize = 100000 
    Dim pic As String 
    Dim bytedata() As Byte 
    Dim sfile As Integer 

    sql = "select PICS from student_record_database " //empty field with no pictures 
    RES.Open sql, CON, adOpenDynamic, adLockOptimistic 
    sfile = App.Path & "/mypic/Book1.xls" //error : type mismatch 

    Open sfile For Binary Access Read As #1 
    filelen = LOF(sfile) 
    If filelen = 0 Then 
    Close sfile 
    MsgBox ("empty or not found") 
    Else 

    numlock = filelen/blocksize 
    leftover = filelen Mod blocksize 
    ReDim bytedata(leftover) 
    Get sfile, , bytedata() 
    RES(1).AppendChunk bytedata() 
    ReDim bytedata(blocksize) 

    For i = 1 To numlock 
     Get sfile, , bytedata() 
     RES(1).AppendChunk bytedata() 
    Next i 

    RES.Update 
    Close sfile 
    End If 
End Function 

'code to display picture in picture box from table 
Private Function ShowPic() 
    Dim bytedata() As Byte 
    Dim file As String 
    Dim filelen As Long 
    Dim numlock As Integer 
    Dim leftover As Long 
    Const blocksize = 100000 

    file = App.Path & "\image1.jpeg" 
    Open file For Binary As #1 
    numlock = filelen/blocksize 
    leftover = filelen Mod blocksize 
    bytedata() = RES(1).GetChunk(leftover) 
    Put file, , bytedata() 

    For i = 1 To numlock 
    bytedata() = RES(1).GetChunk(blocksize) 
    Put file, , bytedata() 
    Next i 
    Close file 
End Function 

這裏是我完整的代碼插入圖片使用vb在oracle表數據庫。 接下來,我根據它們的記錄在vb應用程序的圖片框中顯示這些圖片,但它顯示「類型不匹配」的錯誤,並且圖片未顯示在圖片框中。如何使用vb6和oracle存儲並顯示圖片?

+0

什麼是「顯示錯誤」是什麼意思?請_always_發佈完整的錯誤消息,以便人們不必猜測您的問題是什麼。 – Ben

回答

0

你聲明sFile作爲一個整數,但要加載在一個字符串

Dim sFile as string 
sfile = App.Path & "/mypic/Book1.xls" 
+0

如果我這樣做,那麼它顯示類型不匹配filelen = LOF(sfile)

+0

LOF()期望文件編號,因此應該是:filelen = LOF(1).... btw最好使用FreeFile來獲取唯一的文件編號:intFile = FreeFile ..然後使用intFile而不是1 – Hrqls

+0

有必要給代碼中的? –

相關問題