Microsoft KB Archive/272338

= How to use Visual FoxPro 6.0 and later versions and the ADO Stream object to handle Binary Large Object (BLOB) data =

Article ID: 272338

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 7.0 Professional Edition
 * Microsoft Visual FoxPro 8.0 Professional Edition
 * Microsoft Visual FoxPro 9.0 Professional Edition

-



This article was previously published under Q272338



SUMMARY
Microsoft Visual FoxPro 6.0 and later versions have the capability to handle Binary Large Object (BLOB) data from providers like Microsoft SQL Server by using ActiveX Data Objects (ADO) Stream objects and recordsets.

A BLOB is a type of data column that contains binary data such as graphics, sound, or compiled code. From the perspective of an application, this data is &quot;formless.&quot; In SQL Server, this data is commonly known as an &quot;Image&quot; data type.



MORE INFORMATION
The following code sample assumes that you have the necessary access and privileges to a Microsoft SQL Server, and that you have the pub_info table in the SQL Server 7.0 or SQL Server 2000 Pubs sample database.  In Visual FoxPro, create a new program.  Paste the following code into the new program: CLEAR CLEAR ALL RELEASE ALL
 * 1) DEFINE LOC_SQLSERVERNAME  &quot;MYSERVER&quot;
 * 2) DEFINE LOC_SQLUID     &quot;SA&quot;
 * 3) DEFINE LOC_SQL_PWD &quot;&quot;

LOCAL lcConnStr, lcSQL, loConnection, lcImageName, ; loRecordSet, loADOStream

lcConnStr=&quot;Provider=SQLOLEDB;&quot; +; &quot;Data Source=&quot; + LOC_SQLSERVERNAME + &quot;;&quot; +; &quot;Initial Catalog=PUBS;&quot; +; &quot;UID=&quot; + LOC_SQLUID + &quot;;&quot; +; &quot;Pwd=&quot; + LOC_SQL_PWD

lcSQL = &quot;SELECT * FROM pub_info&quot;

loConnection = CREATEOBJECT(&quot;ADODB.Connection&quot;) loRecordSet = CREATEOBJECT(&quot;ADODB.Recordset&quot;) loADOStream = CREATEOBJECT(&quot;ADODB.Stream&quot;)
 * !* Creates the objects.

loConnection.OPEN(lcConnStr) loRecordSet.OPEN(lcSQL,loConnection,2,3)
 * !* Open the connections.

loADOStream.TYPE = 1   && 1=Binary Data, 2=Text Data. loADOStream.OPEN
 * !* Set Stream Object properties.

loADOStream.WRITE(loRecordSet.FIELDS(&quot;logo&quot;))  && Pass data to the stream object. lcImageName = &quot;BLOB.gif&quot;                       && Sets the local file name. loADOStream.SaveToFile(lcImageName,2)          && Saves stream object to a file. @1,1 SAY CURDIR + lcImageName BITMAP         && Displays image file

loRecordSet.CLOSE loConnection.CLOSE loADOStream.CLOSE
 * !* Close connections.

ERASE CURDIR + &quot;BLOB.gif&quot;  Change the three #DEFINE statements to reflect your local setup, and then save and run the program. Observe the image on the Visual FoxPro desktop.

(c) Microsoft Corporation 2000, All Rights Reserved. Contributions by Reinaldo Torrales, Microsoft Corporation.

