当前位置: 网学 > 编程文档 > VB > 正文

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

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式

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

Private 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  
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal  
nBufferLength As Long, ByVal lpBuffer As String) As Long  
Private Const MAX_PATH = 260  

Private m_DBConn As ADODB.Connection  

Private Const BLOCK_SIZE = 10000  
'' Return a temporary file name.  
Private 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  
Private 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 & "\"  
db_file = db_file & "dbpict.mdb"  

'' Open the database connection.  
Set m_DBConn = New ADODB.Connection  
m_DBConn.Open _  
"Provider=Microsoft.Jet.OLEDB.4.0;" & _  
"Data Source=" & db_file & ";" & _  
"Persist Security Info=False"  

'' Get the list of people.  
Set rs = m_DBConn.Execute("SELECT Name FROM People ORDER BY Name", ,  
adCmdText)  
Do While Not rs.EOF  
lstPeople.AddItem rs!Name  
rs.MoveNext  
Loop  

rs.Close  
Set rs = Nothing  
End Sub  
Private Sub Form_Resize()  
lstPeople.Height = ScaleHeight  
End Sub  


'' Display the clicked person.  
Private Sub lstPeople_Click()  
Dim rs As ADODB.Recordset  
Dim bytes() As Byte  
Dim file_name As String  
Dim file_num As Integer  
Dim file_length As Long  
Dim num_blocks As Long  
Dim left_over As Long  
Dim block_num As L
  • 下一篇资讯: 做个“网络助手”程序
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号