求助:为什么blob字段插入二进制文件,总显示null
Private Sub FileToOLEfield(sFilename As String, OLEField As ADODB.Field)Dim FileNumber As Integer
Dim FileBuffer() As Byte
Dim FileSize As Long
Dim ChunkSize As Long '块大小
Dim Flag As Integer
On Error Resume Next
ChunkSize = 32768
FileNumber = FreeFile
Flag = False
Open sFilename For Binary As FileNumber
FileSize = LOF(FileNumber)
If FileSize > 0 Then
Do Until Flag = True
If (FileSize - Seek(FileNumber)) < ChunkSize Then
ChunkSize = (FileSize - Seek(FileNumber) + 1)
Flag = True
End If
ReDim FileBuffer(ChunkSize) As Byte
Get #FileNumber, , FileBuffer
OLEField.AppendChunk FileBuffer
Loop
End If
Close #FileNumber
End Sub
Private Sub Command1_Click()
CommonDialog1.DialogTitle = "图片资料"
CommonDialog1.Filter = "图片文件(*.JPG;*.bmp;*.gif)|*.JPG;*.bmp;*.gif|所有文件(*.*)|*.*"
CommonDialog1.Action = 1
Image1.Picture = LoadPicture(CommonDialog1.FileName)
Dim DcnNWind As New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
db_host = "192.168.100.232"
connstr = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=" + db_host + ";DATABASE=" + "cp" + _
";UID=" + "sp" + ";PWD=" + "" + ";OPTION=3;stmt=SET NAMES GBK"
DcnNWind.Open connstr
rs.Open "select * from images ", DcnNWind, adOpenKeyset, adLockPessimistic
rs.AddNew
FileToOLEfield CommonDialog1.FileName, rs.Fields("pic")
rs.Update
rs.Close
SaveResourceFile = True
End Sub