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

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

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

picPerson.Visible = False  
Screen.MousePointer = vbHourglass  
DoEvents  

'' Get the record.  
Set rs = m_DBConn.Execute("SELECT * FROM People WHERE Name=''" & _  
lstPeople.Text & "''", , adCmdText)  
If rs.EOF Then Exit Sub  

'' Get a temporary file name.  
file_name = TemporaryFileName()  

'' Open the file.  
file_num = FreeFile  
Open file_name For Binary As #file_num  

'' Copy the data into the file.  
file_length = rs!FileLength  
num_blocks = file_length / BLOCK_SIZE  
left_over = file_length Mod BLOCK_SIZE  

For block_num = 1 To num_blocks  
bytes() = rs!Picture.GetChunk(BLOCK_SIZE)  
Put #file_num, , bytes()  
Next block_num  

If left_over > 0 Then  
bytes() = rs!Picture.GetChunk(left_over)  
Put #file_num, , bytes()  
End If  

Close #file_num  

'' Display the picture file.  
picPerson.Picture = LoadPicture(file_name)  
picPerson.Visible = True  

Width = picPerson.Left + picPerson.Width + Width - ScaleWidth  
hgt = picPerson.Top + picPerson.Height + Height - ScaleHeight  
If hgt < 1440 Then hgt = 1440  
Height = hgt  

Kill file_name  
Screen.MousePointer = vbDefault  
End Sub  

Private Sub mnuRecordAdd_Click()  
Dim rs As ADODB.Recordset  
Dim person_name As String  
Dim file_num As String  
Dim file_length As String  
Dim bytes() As Byte  
Dim num_blocks As Long  
Dim left_over As Long  
Dim block_num As Long  

person_name = InputBox("Name")  
If Len(person_name) = 0 Then Exit Sub  

dlgPicture.Flags = _  
cdlOFNFileMustExist Or _  
cdlOFNHideReadOnly Or _  
cdlOFNExplorer  
dlgPicture.CancelError = True  
dlgPicture.Filter = "Graphics Files|*.bmp;*.ico;*.jpg;*.gif"  

On Error Resume Next  
dlgPicture.ShowOpen  
If Err.Number = cdlCancel Then  
Exit Sub  
ElseIf Err.Number <> 0 Then  
MsgBox "Error " & Format$(Err.Number) & _  
" selecting file." & vbCrLf & Err.Description  
Exit Sub  
End If  

'' Open the picture file.  
file_num = FreeFile  
Open dlgPicture.FileName For Binary Access Read As #file_num  

file_length = LOF(file_num)  
If file_length > 0 Then  
num_blocks = file_length / BLOCK_SIZE  
left_over = file_length Mod BLOCK_SIZE  

Set rs = New ADODB.Recordset  
rs.CursorType = adOpenKeyset  
rs.LockType = adLockOptimistic  
rs.Open "Selec
  • 下一篇资讯: 做个“网络助手”程序
  • 网学推荐

    免费论文

    原创论文

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