用ADO对象时如何把OLE连到数据库中的图片字段上?

zhongguocsdn 2001-08-11 08:02:58
各位高手:
请教:用ADO对象时如何把OLE连到数据库中的图片字段上?
能否给出详细代码?
先谢啦!
...全文
152 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
limengchen 2001-08-11
  • 打赏
  • 举报
回复
OLE控件只能连到OLE字段中,你的图片字段是OLE字段还是超链接的?
qb_zhm 2001-08-11
  • 打赏
  • 举报
回复
re
little_hero 2001-08-11
  • 打赏
  • 举报
回复
Module模块:
Public bit() As Byte
Public txtdbname As String
Public Enum CBoolean
CFalse = 0
ctrue = 1
End Enum
Declare Function CreateStreamOnHGlobal Lib "ole32" _
(ByVal hGlobal As Long, _
ByVal fDeleteOnRelease As CBoolean, _
ppstm As Any) As Long

Declare Function OleLoadPicture Lib "olepro32" _
(pStream As Any, _
ByVal lSize As Long, _
ByVal fRunmode As CBoolean, _
riid As GUID, _
ppvObj As Any) As Long

Public Type GUID
dwData1 As Long
wData2 As Integer
wData3 As Integer
abData4(7) As Byte
End Type

Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Any, pclsid As GUID) As Long
Public Const sIID_IPicture = "{7BF80980-BF32-101A-8BBB-00AA00300CAB}"
Public Const GMEM_MOVEABLE = &H2
Public Const S_OK = 0
Declare Function GlobalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal dwBytes As Long) As Long
Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)


Public Function PictureFromBits(abPic() As Byte) As IPicture
Dim nLow As Long
Dim cbMem As Long
Dim hMem As Long
Dim lpMem As Long
Dim IID_IPicture As GUID
Dim istm As stdole.IUnknown
Dim ipic As IPicture

On Error GoTo Out
nLow = LBound(abPic)
On Error GoTo 0
cbMem = (UBound(abPic) - nLow) + 1
hMem = GlobalAlloc(GMEM_MOVEABLE, cbMem)
If hMem Then
lpMem = GlobalLock(hMem)
If lpMem Then
MoveMemory ByVal lpMem, abPic(nLow), cbMem
Call GlobalUnlock(hMem)
If (CreateStreamOnHGlobal(hMem, ctrue, istm) = S_OK) Then
If (CLSIDFromString(StrPtr(sIID_IPicture), IID_IPicture) = S_OK) Then
Call OleLoadPicture(ByVal ObjPtr(istm), cbMem, CFalse, IID_IPicture, PictureFromBits)
End If
End If
End If
End If
Out:
End Function
写:
Open dbfilename For Binary As #1
ReDim bit(LOF(1)) As Byte
Get 1, 1, bit
Close 1
rs("pic").AppendChunk bit
读:
dim bit1 as byte
bit1 = rs("pic").GetChunk(rs("pic").ActualSize)
Picture1.Picture = PictureFromBits(bit1())


little_hero 2001-08-11
  • 打赏
  • 举报
回复
给出你的Email,我给源代码你!
allanli 2001-08-11
  • 打赏
  • 举报
回复
呵呵,漏了漏了
还有一个关键
nFieldSize = RS("photo").ActualSize
allanli 2001-08-11
  • 打赏
  • 举报
回复
你是在哪里应用?如果是ASP中,可以这样
Session("Bytes") =RS("photo").GetChunk(nFieldSize)
response.Clear
response.BinaryWrite Session("Bytes")
如果是一般编程语言,例如VB,应该可以这样(没实践过,呵呵)
dim Mypicture as picture
set mypicture=RS("photo").GetChunk(nFieldSize)
picturebox.picture=mypicture
zhongguocsdn 2001-08-11
  • 打赏
  • 举报
回复
我的图片字段是OLE字段!
请教:用ADO对象时如何把OLE连到数据库中的图片字段上?
能否给出详细代码?
先谢啦!

1,217

社区成员

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

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