📄 如何把图片放入sql server表中image类型列中.txt
字号:
部 分 代 码 如 下 , 可 将 它 封 装 在 ActiveX Dll中 。
' 将 Binary/Text文 件 内 容 保 存 到 Image/Text字 段
' 输 入 参 数 : Fld Image/Text字 段
' FldDesc 文 件 名 字 段 , 不 包 含 路 径 , 可 选
' DiskFile 文 件 名 , 包 含 文 件 最 初 所 在 的 目 录
Const BLOCKSIZE = 4096
Public Sub SaveToDB(ByRef Fld As ADODB.Field, DiskFile As String, _
Optional ByRef FldDesc As ADODB.Field)
Dim strData As String '用 于 处 理 Text字 段
Dim byteData() As Byte '用 于 处 理 Image字 段
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
Select Case Fld.Type
Case adLongVarBinary 'Image 字 段
ReDim byteData(NumBlocks)
For I = 1 To NumBlocks
Get SourceFile, , byteData()
Fld.AppendChunk byteData()
Next I
ReDim byteData(LeftOver)
Get SourceFile, , byteData()
Fld.AppendChunk byteData()
Case adLongVarChar 'Text 字 段
strData = String(BLOCKSIZE, 32)
For I = 1 To NumBlocks
Get SourceFile, , strData
Fld.AppendChunk strData
Next I
strData = String(LeftOver, 32)
Fld.AppendChunk strData
End Select
Close SourceFile
If Not IsMissing(FldDesc) Then FldDesc.Value = Mid(DiskFile, PosA(DiskFile, "\") + 1)
End If
End Sub
<END>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -