高分请教,一个关于二进制字段的更新问题,答案有效,一定给分!!

Thumb168 2003-08-14 11:28:51
内容很简单,就是在VB下如何把一个文件的内容弄到SQL数据库表的一下二进制字段中。用SQLDMO或ADO二种任何一种式连接数据库都可
用VB不多,所有请大家多多帮忙啊
...全文
4 点赞 收藏 1
写回复
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fling_boy 2003-08-15
Private Function DatabaseToFile(ByVal DataField As ADODB.Field, ByVal vSaveAs As String, ByVal vFileExpendName As String) As String
Dim fnum As Long, bytesleft As Long, bytes As Long
Dim lSumSize As Long, lNowSize As Long
Dim tmp() As Byte
On Error GoTo ErrHandleDatabaseToFile
If Trim(vSaveAs) = "" Then
DatabaseToFile = GetTempFileName(vFileExpendName)
Else
DatabaseToFile = Trim(vSaveAs)
End If

fnum = FreeFile
Open (DatabaseToFile) For Binary As fnum
bytesleft = DataField.ActualSize

lSumSize = CLng(bytesleft / 8192)

Do While bytesleft
bytes = bytesleft
If bytes > 8192 Then bytes = 8192
tmp = DataField.GetChunk(bytes)
Put #fnum, , tmp
bytesleft = bytesleft - bytes
lNowSize = lNowSize + 1
RaiseEvent TransmitData(lNowSize, lSumSize, False)
Loop
Close #fnum
Exit Function
ErrHandleDatabaseToFile:
DatabaseToFile = ""
Err.Clear
End Function

Private Function FileToDatabase(ByVal vDataField As ADODB.Field, ByVal vFileName As String)
Dim fnum As Long, bytesleft As Long, bytes As Long
Dim lSumSize As Long, lNowSize As Long
Dim tmp() As Byte
On Error GoTo ErrHandleFileToDatabase

fnum = FreeFile
Open vFileName For Binary As fnum
bytesleft = LOF(fnum)
lSumSize = CLng(bytesleft / 8192)
Do While bytesleft
bytes = bytesleft
If bytes > 8192 Then bytes = 8192
ReDim tmp(1 To bytes) As Byte
Get #fnum, , tmp
vDataField.AppendChunk tmp
bytesleft = bytesleft - bytes
lNowSize = lNowSize + 1
DoEvents
RaiseEvent TransmitData(lNowSize, lSumSize, True)
Loop

Close #fnum

Exit Function
ErrHandleFileToDatabase:
Err.Clear
End Function
回复
发动态
发帖子

1181

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告