Microsoft Knowledge Base Email Alertz

The MyDynText sample demonstrates how to read and write text data (long binary data) when you use the

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 265125 - Last Review: August 5, 2004 - Revision: 2.3

SAMPLE: MyDynText.exe Allows You to Read and Write Text Data Dynamically with the SQL OLE DB Provider

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:
MyDynText.exe (http://download.microsoft.com/download/ole/other/6.0/w9x2k/en-us/mydyntext.exe)
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  (http://kbalertz.com/Feedback.aspx?kbNumber=119591/EN-US/ ) 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  (http://kbalertz.com/Feedback.aspx?kbNumber=190958/EN-US/ ) 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.

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++, 32-bit Learning Edition 6.0
Keywords: 
kbdownload kbdatabase kbdtl kbfile kbsample KB265125
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate