临时文件
VB把文件从IMAGE字段中读到文件中。
Sub loadpic(IndexNumber As Long)
Dim DcnNWind As New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
DcnNWind.CursorLocation = adUseClient
DcnNWind.Open "Provider=SQLOLEDB.1;Integrated Security=SSI;Persist Security Info=False;Initial Catalog=CUSTOM;Data Source=SERVER "
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open "CustomInfo ", DcnNWind, , adCmdTable
rs.Move (IndexNumber)
Call BlobToFile(rs.Fields( "Image "), "c:\windows\temp\tmp.bmp ", rs.Fields( "Image ").ActualSize)
End Sub
Private Sub BlobToFile(fld As ADODB.Field, FileName As String, Optional ChunkSize As Long )
Dim fnum As Integer, bytesLeft As Long, bytes As Long
Dim tmp() As Byte
If (fld.Attributes And adFldLong) = 0 Then
Err.Raise 1001, , "Field doesn 't support the GetChunk method. "
End If
If Dir$(FileName) <> " " Then Kill FileName
fnum = FreeFile
Open FileName For Binary As fnum
bytesLeft = fld.ActualSize
Do While bytesLeft
bytes = bytesLeft
If bytes > ChunkSize Then bytes = ChunkSize
tmp = fld.GetChunk(bytes)
Put #fnum, , tmp
bytesLeft = bytesLeft - bytes
Loop
Close #fnum
End Sub
临时文件,以下是把图片生成临时文件的,不知道有没有其他方法不生成临时文件?但要能打开这个文件!
[解决办法]
不生成文件又要“打开文件”,很费劲的理解结果好像是显示这个图像吧
添加一个Data数据控件,设置它的DatabaseName和RecordSource属性,
添加Image控件用来显示图片,设置它的DataSource和DataField属性。
就可以显示你要的数据了,什么代码也不用。