VB图片存入SQLServer中

模块:
Dim LngOffset As Long, Chunks As Integer, LngTotaSize As Long
Dim Fragment As Integer, Chunk() As Byte, i As Long
Const ChunkSize As Integer = 2384
Dim Mediatemp As String
Public Function ShowPicture(ByVal DataFile As String, ByVal SQL As String, ByVal SQLZD As String) '显示图片
Dim Rs As New ADODB.Recordset
Rs.Open SQL, DataConn, adOpenKeyset, adLockOptimistic
Rs.MoveLast
Open DataFile For Binary As 1
Chunk = Rs.Fields(SQLZD) '将二进制数据读出写入文件。
Put 1, , Chunk
Close 1
Rs.Close
End Function
Public Function SavePicture4(ByVal DataFile As String, ByVal SQL As String, ByVal SQLZD As String) As Integer '保存图片
Dim Rs As New ADODB.Recordset
If DataFile = "" Then
  Exit Function: SavePicture4 = 0
End If
Open DataFile For Binary As 1
Rs.Open SQL, DataConn, adOpenKeyset, adLockOptimistic
If FileLen(DataFile) = True Then Close 1: Exit Function: SavePicture4 = 0 '文件大小为零的处理
Chunks = FileLen(DataFile) / ChunkSize
Fragment = FileLen(DataFile) Mod ChunkSize
ReDim Chunk(Fragment) '根据文件长度定义动态数组大小
Get 1, , Chunk() '将一个已打开的磁盘文件读入数组变量之中
Rs.Update
Rs.Fields(SQLZD).AppendChunk Chunk()
'将得到的值写入数据库
ReDim Chunk(ChunkSize)
   For i = 1 To Chunks
      Get 1, , Chunk()
      Rs.Fields(SQLZD).AppendChunk Chunk()
      '将得到的值写入数据库
    Next i
Close 1
Rs.Update
Rs.Close
SavePicture4 = 1
End Function


使用方法:
保存:
 SQL = "SELECT * FROM T_Stuent_Info WHERE Code='" & Trim(Text1(0).Text) & "'"
            a = SavePicture4(Text3.Text, SQL, "Photo") '保存图片
显示:
SQL = "SELECT Photo FROM T_Stuent_Info WHERE Code='" & Trim(Text1(0).Text) & "'"
Text3.Text = "C:/Temp.jpg"
Call ShowPicture("C:/Temp.jpg", SQL, "Photo")
然后调用生成的这个临时图片就可以了.  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值