The following file is available for download from the Microsoft Download Center:
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.
Using CreateRecordset
CreateRecordset requires a Variant of type VT_VARIANT|VT_ARRAY as a
parameter, which describes the schema of the table. Each element of this
SAFEARRAY holds another SAFEARRAY of variants describing each field. Each
element of the field array must be of a specific vt VARIANT type or
CreateRecordset returns an "Invalid Argument" or a "Wrong Parameter
Type" error.
To begin with, each field in the new recordset requires a four-element
safearray of variants. The elements represent the Field Name, the Field
Type, the Field Length, and whether or not the Field is nullable,
respectively.
The first element must have a type of VT_BSTR, the second element must have
a type of VT_I2 and a value that corresponds to one of the ADO data types
(you can find these in the header files, for example, adVarChar = 200). The
third element has a type of VT_I2 and a value equal to the length of the
field, and the fourth element has a type of VT_BOOL and a value of
VARIANT_FALSE OR VARIANT_TRUE, depending on whether or not the "Not Null"
property of the field should be set.
Once the safearrays for each field are built, another safearray must be
built that will be the Schema of the recordset. The Schema Safearray
(psaRecord in the sample) will be an array of variants and will have as
many elements as the recordset will have fields. Set the type of each
element in this array to VT_VARIANT | VT_ARRAY and load up each element
with one of the field arrays above.
Finally, create a final variant that will hold the schema array (varRecord
in the sample). Set the type to VT_ARRAY |VT_VARIANT and the value to the
schema array. This is the parameter that will be passed to CreateRecordset.
Notes on the TestRecordset Sample
The sample does not use MFC, in the interests of simplicity and clarity. It
does, however, use smartpointers and objects such as _variant_t and
_bstr_t. These objects greatly simplify reference counting and scoping.
The sample also shows how to Add Records and then read through them.
Several problems using RDS in Visual C++ and their workarounds are
documented in the code comments, and should be read carefully.
In the version 2.5 and later of ADO/RDS there is an alternative to CreateRecordset. Simply create the recordset object, as in the sample. Then for each field in the recordset, create a Field object, fill in the required properties such as Name, Type, Length, etc, and Append the field to the Recordset. When all fields have been appended, simply Open the recordset and start adding data with AddNew, as in the sample.