数据库中图片的显示

zjhz160 2004-01-04 11:50:10
请问各位高手,如何在窗体中显示数据库中指定的一张或几张图片,即我要在一个窗体中显示数据库中第一到第十张图片,点击“下一页”后,显示第十一到第二十张图片,以此类推。
谢谢了,我很急!
...全文
19 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
vbman2003 2004-01-05
  • 打赏
  • 举报
回复
不好意思,疏忽了!应该是:
For i = 0 To n - 1
......
Next i
vbman2003 2004-01-05
  • 打赏
  • 举报
回复
lichen720(晨晨)的 Command4_Click()事件中已说明了图像保存到数据库中的方法
我就谈谈同时显示n幅图像的想法,供你参考
数据库:db1.mdb;保存图像的表:picture_info;表中两个字段:ID(自动编号)、Picture(OLE)
VB窗体中n个Picture控件数组,用来同时显示n幅图像

Option Explicit
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StmPic As ADODB.Stream
Dim StrPicTemp As String
Dim i As Integer

Private Sub Form_Load()
Set conn = New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Persist Security Info=False"
Set rs = New ADODB.Recordset
rs.Open "select * from picture_info", conn, adOpenKeyset, adLockOptimistic
End Sub

Private Sub cmdShow_Click() ‘单击按钮同时显示n幅图像
For i = 0 To n
If Not rs.EOF Then
If Not IsNull(rs.Fields(1)) Then
Set StmPic = New ADODB.Stream
StrPicTemp = "c:\temp.tmp" '临时文件,用来保存读出的图片
With StmPic
.Type = adTypeBinary '二进制类型
.Open '打开
.Write rs.Fields(1) '写入数据库中的二进制文件
.SaveToFile StrPicTemp, adSaveCreateOverWrite '保存读出的图片到临时文件中
.Close
End With
Picture1(i).Picture = LoadPicture(StrPicTemp) '载入临时文件中的图像
End If
rs.MoveNext
Else
rs.MoveFirst
End If
Next
End Sub

Private Sub cmdEnd_Click()
rs.Close
conn.Close
End
End Sub


疯狂低调 2004-01-04
  • 打赏
  • 举报
回复
使用ADODB.Stream将图片读入数据库,
或者使用其将图片读出到本地硬盘,然后适用加载图片的方式!
lichen720 2004-01-04
  • 打赏
  • 举报
回复
图片保存在数据库中

用VB程序将图片保存到数据库 SQL SERVER 中,并从数据库中读出该图片。
Private Sub Command3_Click()
Dim c As New ADODB.Connection
c.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\1.mdb;Persist Security Info=False"
c.Execute "create table a (b longbinary)"
End Sub

Private Sub Command4_Click()
Set b = New ADODB.Recordset
Set c = New ADODB.Stream


c.Mode = adModeReadWrite

c.Type = adTypeBinary
c.Open
c.LoadFromFile "c:\1.bmp"

b.Open "select * from a", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\1.mdb;Persist Security Info=False", adOpenDynamic, adLockOptimistic
b.AddNew

b.Fields.Item(0).Value = c.Read()


b.Update

b.Close
Set b = New ADODB.Recordset
b.Open "select * from a", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\1.mdb;Persist Security Info=False", adOpenKeyset, adLockOptimistic
MsgBox b.RecordCount

b.MoveLast

c.Write (b.Fields.Item(0).Value)

c.SaveToFile "c:\aa.bmp", adSaveCreateOverWrite

Picture1.Picture = LoadPicture("c:\aa.bmp")
End Sub




'Use ADODB.Stream Method
'After ADO 2.6
'Import the Image to SQLServer
Private Sub ImportBLOB(cn As ADODB.Connection)

Dim rs As New ADODB.Recordset
Dim stm As ADODB.Stream

Set stm = New ADODB.Stream

' Skip any table not found errors
On Error Resume Next
cn.Execute "drop table BinaryObject"

On Error GoTo 0
'Create the BinaryObject table
cn.Execute "create table BinaryObject " & _
"(blob_id int IDENTITY(1,1), " & _
"blob_filename varchar(256), " & _
"blob_object image)"

rs.Open "Select * from BinaryObject where 1=2", cn, adOpenKeyset, adLockOptimistic
'Read the binary files from disk
stm.Type = adTypeBinary
stm.Open
stm.LoadFromFile App.Path & "\BLOBsample.jpg"

rs.AddNew
rs!blob_filename = App.Path & "\BLOBsample.jpg"
rs!blob_object = stm.Read

'Insert the binary object in the table
rs.Update

rs.Close
stm.Close

Set rs = Nothing
Set stm = Nothing

End Sub
'Display the image on image control
Private Sub DisplayBLOB(cn As ADODB.Connection)

Dim rs As New ADODB.Recordset

' Select the only image in the table
rs.Open "Select * from BinaryObject where blob_id = 1", cn

' Set the DataSource to the recordset
Set imgBinaryData.DataSource = rs
'Set the DataField to the BLOB field
imgBinaryData.DataField = rs!blob_object.Name

'Release the recordset
rs.Close
Set rs = Nothing

End Sub
火电 2004-01-04
  • 打赏
  • 举报
回复
sql语句的问题
你的图片是否作为数据库的记录保存的

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧