国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
VB在Oracle數(shù)據(jù)庫中存取文件

VB在Oracle數(shù)據(jù)庫中存取文件

oracle中可用LOB 字段來存儲長文本或者二進(jìn)制數(shù)據(jù),LOB分為BLOB合CLOB,其中BLOB可用來存儲二進(jìn)制數(shù)據(jù),如exe、dll、視頻、音頻等;CLOB只能用來存儲字符型文本數(shù)據(jù)。
舉個(gè)VB存取BLOB字段的簡單例子,首先在oracle中建一有BLOB字段的表
SQL:
create table TEST_TABLE(id number(4) not null,fileName varchar2(255),fileContent BLOB)

在VB中寫代碼:
Dim cnn As New ADODB.Connection     '全局?jǐn)?shù)據(jù)
Dim rs1 As New ADODB.Recordset      '全局?jǐn)?shù)據(jù)
Dim SQL As String                   '全局?jǐn)?shù)據(jù)

Private Sub Command1_Click()
   SaveFile ("D:\7.JPG")
End Sub

Private Sub Command2_Click()
    GetFile
End Sub

Private Sub Form_Load()
    cnn.ConnectionString = "Provider=OraOledb.Oracle.1;" _
                        & "Password=mygps;" _
                        & "User ID=usermygps;" _
                        & "Data
Source=mygps@mygps;" _
                        & "Persist Security Info=True"
    cnn.Open       '打開數(shù)據(jù)庫連接
End Sub

'-------------插入一條記錄,存儲文件數(shù)據(jù)-----------------
Private Sub SaveFile(strFileName As String)
        rs1.LockType = adLockOptimistic
        rs1.CursorLocation = adUseClient
        rs1.Open "TEST_TABLE", cnn, adCmdTable
        rs1.AddNew
        rs1.Fields("id").Value = 1
        rs1.Fields("fileName").Value = strFileName
        Call FileToBlob(rs1.Fields("fileContent"), strFileName)
        rs1.Update
       rs1.Close
       Set rs1 = Nothing
End Sub

'-------------讀取一條記錄,獲取文件數(shù)據(jù),并寫入文件-----------
Private Sub GetFile()
    strSql = "select * from TEST_TABLE where id='2'"
    Debug.Print strSql
    rs1.LockType = adLockOptimistic
    rs1.CursorLocation = adUseClient
    rs1.Open strSql, cnn, adOpenKeyset
    If rs1.RecordCount > 0 Then
       BlobToFile rs1.Fields("fileContent"), rs1.Fields("fileName").Value, rs1.Fields("fileContent").ActualSize
    End If
    rs1.Close
    Set rs1 = Nothing
End Sub

'-------------文件數(shù)據(jù)轉(zhuǎn)BLOB----------------------
Private Sub FileToBlob(fld As ADODB.field, FileName As String, Optional ChunkSize As Long = 8192)
    Dim fnum As Integer, bytesLeft As Long, bytes As Long
    Dim tmp() As Byte
   
    If (fld.Attributes And adFldLong) = 0 Then
        Err.Raise 1001, , "Field doesn't support the GetChunk method."
    End If
   
    fnum = FreeFile
    Open FileName For Binary As fnum
   
    bytesLeft = LOF(fnum)
    Do While bytesLeft
        bytes = bytesLeft
        If bytes > ChunkSize Then bytes = ChunkSize
       
        ReDim tmp(1 To bytes) As Byte
        Get #1, , tmp
        fld.AppendChunk tmp
        bytesLeft = bytesLeft - bytes
    Loop
    Close #fnum
End Sub

'-------------BLOB數(shù)據(jù)轉(zhuǎn)存文件---------------------
Private Sub BlobToFile(fld As ADODB.field, FileName As String, Optional ChunkSize As Long)
    Dim fnum As Integer, bytesLeft As Long, bytes As Long
    Dim tmp() As Byte
   
    If (fld.Attributes And adFldLong) = 0 Then
        Err.Raise 1001, , "Field doesn't support the GetChunk method."
    End If
   
    If Dir$(FileName) <> "" Then Kill FileName
   
    fnum = FreeFile
    Open FileName For Binary As fnum
    bytesLeft = fld.ActualSize
    Do While bytesLeft
        bytes = bytesLeft
        If bytes > ChunkSize Then bytes = ChunkSize
       
        tmp = fld.GetChunk(bytes)
        Put #fnum, , tmp
        bytesLeft = bytesLeft - bytes
    Loop
    Close #fnum
End Sub

 

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
用VB6的雙通道技術(shù)獲得影碟片斷
VB連接ORACLE數(shù)據(jù)庫
VB打開EXCEL的方法
詳解VB.net文件傳輸.(可傳輸任意文件)
VB 打開Word文件
VB.Net處理文本文件的方法
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服