Microsoft KB Archive/265125

From BetaArchive Wiki

Article ID: 265125

Article Last Modified on 8/5/2004



APPLIES TO

  • Microsoft OLE DB 2.7, when used with:
    • Microsoft Visual C++ 6.0 Enterprise Edition
    • Microsoft Visual C++ 6.0 Professional Edition
    • Microsoft Visual C++ 6.0 Standard Edition



This article was previously published under Q265125

SUMMARY

The MyDynText sample demonstrates how to read and write text data (long binary data) when you use the CDynamicAccessor class that is part of the Active Template Library (ATL) OLE DB Consumer template classes.

NOTE: This sample code has only been tested against the Microsoft SQL Server though the Microsoft OLE DB provider for SQL Server (SQLOLEDB).

MORE INFORMATION

The following file is available for download from the Microsoft Download Center:

Release Date: August 30, 2000

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services


Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

Steps to Run the Sample Code

  1. Run the provided Table.sql file on your SQL Server. Once you run this file successfully, the script creates a table named "DynText" on the target database, and then adds one row of data into the DynText table.
  2. Change the connection string to point to your SQL Server in both the OnGet and OnSave button handlers of the dialog box.
  3. Compile the provided sample code, and then run it.


The CDynamicAccessor Class

The CDynamicAccessor class dynamically creates an accessory at run time based on the column information of the rowset. This class is used to retrieve data from a data source with an unknown structure.

Because the buffer is both created and managed by the CDynamicAccessor class, data is obtained from the buffer when you use the GetValue function. If there are Binary Large Objects (BLOB) fields, then you need to get a pointer to the ISequentionalStream interface of the current row.


Reading BLOB Data with the CDynamicAccessor class

To read data from the BLOB field, call the Read method of the ISequentialStream interface in a loop until there is not any more data sent by the OLE DB provider.

NOTE: Most providers do not provide you with the total length of the data prior to reading the data, you must build a buffer dynamically to hold the data as you read it.


Writing BLOB Data with the CDynamicAccessor class

To write to a BLOB field, you must release the pointer provided to you by the OLE DB provider. Get a pointer to the ISequentialStream through the custom buffer that was built when the data was read, and then save your BLOB data into that buffer though the ISequentialStream::Write method. Assign this data into the BLOB column on the server.


To simplify the reading and writing of BLOB data with OLE DB, the MyDynText sample uses the helper class (CISSHelper). For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

190958 AOTBLOB Read/Writes BLOB Using OLE DB Consumer Template


NOTE: The sample code MyDynText demonstrates how to read and write one row of data to a table only. You can modify the sample to add more rows to the table, and then enable scrolling back and forth between different rows.


Additional query words: MyDynText

Keywords: kbdownload kbdatabase kbfile kbsample kbdtl KB265125