HOWTO: Determine Recordset Field Properties Using ADO

ID: Q193947


The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 6.0
  • Microsoft Data Access Components version 2.1 SP2


SUMMARY

In an application, sometimes it is useful to determine the properties of fields in a remote datasource. You can determine information such as the field names, data types and field lengths by examining the Fields collection of the ActiveX Data Objects (ADO) Recordset object.


MORE INFORMATION

The following program creates a Recordset from the Authors table of the SQL Server sample Pubs database. It displays the field name, data type, and defined length of each field in the Authors table.

The data type returns as an integer value. The #DEFINE statements at the top of the program are included so that this value can be cross- referenced to a character description of the data type.

In order to use this example, you must have the Microsoft Data Access Components (MDAC) version 2.x or later installed, which is included in the data components of Visual Studio 6.0 or can be downloaded from the following Web address:

http://www.microsoft.com/data/
NOTE: Substitute values for the SERVER, user id (UID) and password (PWD) values appropriate to your SQL Server installation in the oRecordset.OPEN statement.

Sample Code


   * DEFINEs for field types - provided for reference only.
   #DEFINE ADEMPTY               0
   #DEFINE ADTINYINT            16
   #DEFINE ADSMALLINT            2
   #DEFINE ADINTEGER            3
   #DEFINE ADBIGINT            20
   #DEFINE ADUNSIGNEDTINYINT      17
   #DEFINE ADUNSIGNEDSMALLINT      18
   #DEFINE ADUNSIGNEDINT         19
   #DEFINE ADUNSIGNEDBIGINT      21
   #DEFINE ADSINGLE            4
   #DEFINE ADDOUBLE            5
   #DEFINE ADCURRENCY            6
   #DEFINE ADDECIMAL            14
   #DEFINE ADNUMERIC            131
   #DEFINE ADBOOLEAN            11
   #DEFINE ADERROR               10
   #DEFINE ADUSERDEFINED         132
   #DEFINE ADVARIANT            12
   #DEFINE ADIDISPATCH            9
   #DEFINE ADIUNKNOWN            13
   #DEFINE ADGUID               72
   #DEFINE ADDATE               7
   #DEFINE ADDBDATE            133
   #DEFINE ADDBTIME            134
   #DEFINE ADDBTIMESTAMP         135
   #DEFINE ADBSTR               8
   #DEFINE ADCHAR               129
   #DEFINE ADVARCHAR            200
   #DEFINE ADLONGVARCHAR         201
   #DEFINE ADWCHAR               130
   #DEFINE ADVARWCHAR            202
   #DEFINE ADLONGVARWCHAR         203
   #DEFINE ADBINARY            128
   #DEFINE ADVARBINARY            204
   #DEFINE ADLONGVARBINARY         205
   #DEFINE ADCHAPTER            136

   oRecordSet = CREATEOBJECT("ADODB.Recordset")

   lcSQL = "select * from authors"

   oRecordSet.OPEN(lcSQL, ;
      "DRIVER={SQL Server};" + ;
      "SERVER=YourServerName;" + ;
      "DATABASE=pubs;" + ;
      "UID=YourUserID;" + ;
      "PWD=YourPassword")

   lcFieldInfo = ""
   FOR EACH FIELD IN oRecordSet.FIELDS
      ? "Field name: ", FIELD.NAME, ;
         " Type: ", LTRIM(STR(FIELD.TYPE)), ;
         " Defined size: ", LTRIM(STR(FIELD.DEFINEDSIZE)), ;
         " Actual size: ", LTRIM(STR(FIELD.ACTUALSIZE))
      ?
   NEXT 

Additional query words: kbVFp600 kbActiveX kbSQL kbADO kbCtrl kbMDAC definedsize actualsize ADO

Keywords : kbDatabase kbGrpFox kbGrpMDAC kbDSupport kbADO210sp2 kbMDAC210SP2
Version : WINDOWS:2.1 SP2,6.0
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: November 10, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.