发新话题
打印

如何用VB6读写数据库中的图片

如何用VB6读写数据库中的图片

  很多人问关于VB6读写数据库中的图片的问题,在此有一例,希有所启发。  
1,以人名和相关图片为例说明,数据库为Access,有如下字段:Name  
char,picture OLE object,FileLength Number。当为ms sql时,将picture改为lob即
可。  
2,示例包含control:commom dialog,picture,listbox。  
源码如下:  
Option Explicit  

** Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA"  
(ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long,  
ByVal lpTempFileName As String) As Long  
** Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal  
nBufferLength As Long, ByVal lpBuffer As String) As Long  
** Const MAX_PATH = 260  

** m_DBConn As ADODB.Connection  

** Const BLOCK_SIZE = 10000  
' Return a temporary file name.  
** Function TemporaryFileName() As String  
Dim temp_path As String  
Dim temp_file As String  
Dim length As Long  

' Get the temporary file path.  
temp_path = Space$(MAX_PATH)  
length = GetTempPath(MAX_PATH, temp_path)  
temp_path = Left$(temp_path, length)  

' Get the file name.  
temp_file = Space$(MAX_PATH)  
GetTempFileName temp_path, "per", 0, temp_file  
TemporaryFileName = Left$(temp_file, InStr(temp_file, Chr$(0)) - 1)  
End Function  
** Sub Form_Load()  
Dim db_file As String  
Dim rs As ADODB.Recordset  

' Get the database file name.  
db_file = App.Path  
If Right$(db_file, 1) <> "\" Then db_file = db_file

TOP

发新话题