为什么我的图片无法显示的??? 我的图片是从数据库中读取的(二进制) 写入时也是写到数据库中的,但读取时就无法读出那个图片.. 请问高手这个为什么?? 写入代码: If (Dir(Trim(txtFilePath.Text)) = "") Then Exit Sub '以二进制方式打开文件 If Trim(txtFilePath.Text) <> "" Then Open Trim(txtFilePath.Text) For Binary Access Read As lngDataFile lngLengh = LOF(lngDataFile) ' 文件大小 If lngLengh = 0 Then Close lngDataFile: Exit Sub intChunks = lngLengh \ ChunkSize intFragment = lngLengh Mod ChunkSize ReDim Chunk(intFragment) Get lngDataFile, , Chunk() rs!picname.AppendChunk Chunk() ReDim Chunk(ChunkSize) For i = 1 To intChunks Get lngDataFile, , Chunk() rs!picname.AppendChunk Chunk() Next i Close lngDataFile 读出代码: Dim Chunk() As Byte Dim lngLengh As Long Dim intChunks As Integer Dim intFragment As Integer Const ChunkSize = 1000 Const lngDataFile = 1
Private Sub DisplayBLOB(cn As ADODB.Connection)
Dim rs As New ADODB.Recordset rs.Open "Select * from ajwftzs where ajdsr ='" & ModifyBkFlag1 & "'", cn Set Image1.DataSource = rs Image1.DataField = rs!picname.Name rs.Close Set rs = Nothing End Sub Private Sub Form_Load() Dim rs As New ADODB.Recordset Dim sqlType As String Dim sql As String Dim aa As String rs.LockType = adLockOptimistic rs.CursorType = adOpenKeyset sql = "select picname from ajwftzs where ajdsr ='" & ModifyBkFlag1 & "'" Set rs = TransactSQL(sql) If (rs.BOF = True) And (rs.EOF = True) Then Exit Sub Call ShowPic End Sub
Public Sub ShowPic() On Error Resume Next Open "pictemp" For Binary Access Write As lngDataFile lngLengh = rs!picname.ActualSize intChunks = lngLengh \ ChunkSize intFragment = lngLengh Mod ChunkSize ReDim Chunk(intFragment) Chunk() = rs!picname.GetChunk(intFragment) Put lngDataFile, , Chunk() For i = 1 To intChunks ReDim Chunk(ChunkSize) Chunk() = rs!picname.GetChunk(ChunkSize) '建立图片临时文件 Put lngDataFile, , Chunk() Next i Close lngDataFile FileName = "pictemp" Image1.Picture = LoadPicture(FileName) End Sub
不知哪出错了??
[此贴子已经被作者于2005-5-19 10:56:08编辑过]