vb6.0使用二进制的方法将图片存入sql 2000数据库,想实现编辑图片的功能,可是不知道怎么对存入的二进制字段进行编辑或清除
存图片代码:
Public Sub SaveToDB(ByRef Fld As ADODB.Field, DiskFile As String)
'定义数据块数组
Dim byteData() As Byte
'定义数据块个数
Dim NumBlocks As Long
Dim FileLength As Long
'定义剩余字节长度
Dim LeftOver As Long
Dim SourceFile As Long
Dim i As Long
'判断文件是否存在
If Dir(DiskFile) <> "" Then
SourceFile = FreeFile
'打开二进制文件
Open DiskFile For Binary Access Read As SourceFile
FileLength = LOF(SourceFile)
'判断文件是否空
If FileLength = 0 Then
Close SourceFile
MsgBox DiskFile & "文件无内容,请重新指定文件!", vbExclamation, "注意"
Else
'得到数据块的个数
NumBlocks = FileLength \ BLOCKSIZE
'得到剩余字节数
LeftOver = FileLength Mod BLOCKSIZE
Fld.Value = Null
ReDim byteData(BLOCKSIZE)
For i = 1 To NumBlocks
Get SourceFile, , byteData()
'用Appendchunk方法将byteData()数据写入FLD
Fld.AppendChunk byteData()
DoEvents
Next i
'将剩余数据写入FLD
ReDim byteData(LeftOver)
Get SourceFile, , byteData()
Fld.AppendChunk byteData()
Close SourceFile
End If
Else
MsgBox "文件不存在,请重新指定文件!", vbExclamation, "注意"
End If
End Sub
Private Sub cmdOK_Click()
If Not cdlgPic.FileName = "" Then
Call SaveToDB(arEquip("picture"), cdlgPic.FileName)
End If
arEquip.Update
Unload Me
End Sub
存图片代码:
Public Sub SaveToDB(ByRef Fld As ADODB.Field, DiskFile As String)
'定义数据块数组
Dim byteData() As Byte
'定义数据块个数
Dim NumBlocks As Long
Dim FileLength As Long
'定义剩余字节长度
Dim LeftOver As Long
Dim SourceFile As Long
Dim i As Long
'判断文件是否存在
If Dir(DiskFile) <> "" Then
SourceFile = FreeFile
'打开二进制文件
Open DiskFile For Binary Access Read As SourceFile
FileLength = LOF(SourceFile)
'判断文件是否空
If FileLength = 0 Then
Close SourceFile
MsgBox DiskFile & "文件无内容,请重新指定文件!", vbExclamation, "注意"
Else
'得到数据块的个数
NumBlocks = FileLength \ BLOCKSIZE
'得到剩余字节数
LeftOver = FileLength Mod BLOCKSIZE
Fld.Value = Null
ReDim byteData(BLOCKSIZE)
For i = 1 To NumBlocks
Get SourceFile, , byteData()
'用Appendchunk方法将byteData()数据写入FLD
Fld.AppendChunk byteData()
DoEvents
Next i
'将剩余数据写入FLD
ReDim byteData(LeftOver)
Get SourceFile, , byteData()
Fld.AppendChunk byteData()
Close SourceFile
End If
Else
MsgBox "文件不存在,请重新指定文件!", vbExclamation, "注意"
End If
End Sub
Private Sub cmdOK_Click()
If Not cdlgPic.FileName = "" Then
Call SaveToDB(arEquip("picture"), cdlgPic.FileName)
End If
arEquip.Update
Unload Me
End Sub
update table set img1=null where ......编辑:
打开图像用程序编辑后,重新更新到数据库中
set picture=null 之后,再存入图片就读不出来了
用ado的stream,还以为vb里没有流呢。