Grab a SQL Image data type with the Connector, ODBC or Microsofts ADO

原创 2004年10月27日 10:42:00
Sub Initialize

'How do I read an image from SQL Server and put it in a document?
'How do i get a picture form SQL Server and write it to disk?
' WITHOUT 3rd party software? Yes, free.
'In this example, I read a blob (image data, stored in JPG format) from
'SQL Server and write it to disk,
'as well as embedding it in a notesDocument

'MAKE SURE YOU PUT Uselsx "*lsxlc" in the option section,
'and always use option explicit for your own safety, mkaaay?
' you need mdac_typ.exe (MS data access components) installed where the
'script executes ( to set up odbc DSN)

' I know some folks want to do the reverse of this, and I think it's
'doable. you might need to use
' the SetFormatStream method for the LCField object. If you figure it out,
'could you email me?
' thanks,
'- lucas

' Stuff you almost always need
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
'Stuff for the lsxlc
Dim LCsession As New LCSession
Dim fld As LCField
Dim fldLst As New LCFieldList
Dim fld2 As New lcField(LCTYPE_BINARY)
' not sure if i have to specify binary here
Dim keyFldLst As New LCFieldList
Dim src As New LCConnection ("odbc2")
' why odbc2 ? i dunno , but it works

' Stuff for the new notes doc & attachment
Dim strPic As String
Dim doc As notesDocument
Dim rt As notesRichTextItem
Dim object As NotesEmbeddedObject

Dim x

'Set the connection properties
src.server="epi5" ' Then name of my odbc DSN (using odbcad32.exe)
src.Userid = "yourmom" ' this may already be in the DSN, but what the heck
src.Password = "isso" ' this may already be in the DSN, but what the heck
src.Metadata = "GA_IMAGE" ' my table name
src.Connect ' this, uh... connects i think

' Now specify the keys.
Call keyFldLst.append("*",LCTYPE_TEXT) ' This (*) enables me to get all
'the fields. you could do some key searching and stuff if you really wanted to
' Now issue the select statement
x = src.Select (keyFldLst, 1, fldLst) ' fldLst is populated with fieldNames

Set fld = fldLst.getField(1) ' the employee id field in my case. You
'HAVE to use the ordinal... yuck. I just looked in
'Debug to find the right field. Whatever.
Set fld2 = fldLst.getField(7) ' my BLOB, or image field (stored in jpg format)

' Now (finally) we can get some data
x= src.fetch(fldLst) ' fldlst is populated with values
Do While x <> 0
'Create a file for each employee
strPic = "C:/pictureDirectory/" + fld.text(0) + ".jpg"
Open strPic For Binary As #1
' Write the picture data to the file (look mom ... no GETCHUNK !)
Put #1 ,, fld2.value(0)
Close #1
'Now, create a notesDoc for each picture
Set doc = New notesDocument(db)
'CreateThe body
Set rt = New notesRichTextItem(doc,"body")
'Embed the pic (you can create as an object if you REALLY want to,
' but I needed the file on disk anyway)
Set object = rt.EmbedObject( _
EMBED_OBJECT, "", strPic, "person_image" )
' I could MAIL it,
' or embed a hyperlink to the file i created...
' the possibilities are endless
' today,I'll just save it.
' get the next rec

'Refer to lsxlc.nsf for lsx documentation

End Sub


       有很多种使用数据库的方法,对大多数数据库来说,选择C++这种产品也许并不适宜。我们知道,像dBASE IV,FoxPro,Oracle和Access这样的产品是完全以数据库管理为中心的。...
  • justmuch
  • justmuch
  • 2006年04月10日 21:22
  • 4624


ODBC和ADO区别、ODBC(Open DataBase Connection)开放式系统互连,是一种数据库访问协议,提供了访问数据库的API接口。基于ODBC的应用程序,对数据库操作不依赖于具体的...
  • mythic_y
  • mythic_y
  • 2010年11月18日 19:11
  • 13784


ODBC(Open Database Connection,开放式数据互连)是访问数据库的一个统一接口标准,它允许开发人员使用ODBC API(应用程序接口)来访问多种不同的数据源,并执行数据操作。 ...
  • foreverhuylee
  • foreverhuylee
  • 2014年05月16日 11:21
  • 979

【MySQL】 ODBC connector5.3.4 安装失败

今天安装mysql-installer-community-其中有一个提示失败 Connector/ODBC 5.3.4 Failed 网上查了一下原因是: 需要安装Micros...
  • JCRunner
  • JCRunner
  • 2015年08月10日 18:01
  • 11443


  • bigpower521
  • bigpower521
  • 2015年11月27日 15:25
  • 261

perl 之于ODBC 又或者ADO?

  • wineceramic
  • wineceramic
  • 2006年03月14日 12:02
  • 752


  • wangyy130
  • wangyy130
  • 2014年05月26日 19:45
  • 2050


 数据库的ODBC连接,ADO和BDE有什么区别和联系? 悬赏分:0 - 解决时间:2006-11-24 11:26.提问者: zwl232 - 助理 二级 最佳答案ADO与BDE区别比较大的 ADO...
  • happypolo
  • happypolo
  • 2008年12月11日 00:20
  • 955


  • eit520
  • eit520
  • 2014年06月10日 16:01
  • 3175


ADO【ActiveX Data Objects】应用层的数据访问接口(API【Application Programming Interface,应用程序编程接口】)用以实现访问关系或非关系数据库中...
  • huanghi11
  • huanghi11
  • 2015年02月09日 10:12
  • 1443
您举报文章:Grab a SQL Image data type with the Connector, ODBC or Microsofts ADO