The information in this article applies to:
SUMMARY
The CreateRS.exe sample contains a TestRecordset.cpp file, which shows how
to use the CreateRecordset() method of the Remote Data Services Datafactory
or Data Control to create a new recordset that is not based on an existing
table. This can be useful, for instance, when you want to input data from a
non-standard source (such as instrumentation data from a serial port) and
return a recordset with this data to the RDS Client.
MORE INFORMATIONThe following file is available for download from the Microsoft
Download Center. Click the file name below to download the file: CREATERS.exeFor more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. Using CreateRecordsetCreateRecordset 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 SampleThe 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. REFERENCESRDS documentation does not cover Visual C++. However, it is useful for a description of what the functions/properties of the objects do. Also, the .tli and .tlh files that the #import directive creates will provide the specific Visual C++ syntax for a method call. Additional query words: kbVC kbVC600 kbRDS
Keywords : kbfile kbsample kbDatabase kbGrpVCDB kbGrpMDAC kbDSupport |
Last Reviewed: November 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |