Re: Number of columns in an ADO recordset



"Iwanow" <kpalak@xxxxx> wrote in message
news:1141395680.093652.200620@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,

Pardon me for a newbie question.

I access first column of an ADO recordset object by calling rs(0), the
second column - by rs(1), and so on... This works well as long as I now
number of columns in the recordset.

A problem may occur when I process data brought from an SQL source with
"select * ..." query. If number of columns in the SQL DB changes, the
recordset my crash with a runtime error 3265 (attempting to access
non-existing part of a recordset).

Is there any way to retrive number of columns from a recently populated
recordset? And how to distinguish them if they are reordered (maybe
some column label)?


You might want to take a look at what VB's Object Browser can tell you
about the RecordSet object...

Dim fld as ADODB.Field

' Number of columns
Debug.Print rs.Fields.Count

' Detailed data for each column
For Each fld In rs.Fields
Debug.Print fld.ActualSize
Debug.Print fld.Attributes
Debug.Print fld.DataFormat
Debug.Print fld.DefinedSize
Debug.Print fld.Name
Debug.Print fld.NumericScale
Debug.Print fld.OriginalValue
Debug.Print fld.Precision
Debug.Print fld.Properties
Debug.Print fld.Status
Debug.Print fld.Type
Debug.Print fld.UnderlyingValue
Debug.Print fld.Value
Next fld

--
Dag.


.



Relevant Pages

  • Recordset not updatable
    ... I found a help file that shows an ado recordset object being applied to a forms recordset. ... Set cmd = New ADODB.Command ...
    (microsoft.public.access.formscoding)
  • Re: ADO DBASE Seek
    ... The VCL Seek method is a direct implementation ... of the Seek method for the ADO Recordset object. ...
    (borland.public.delphi.database.ado)
  • Re: BatchUpdate with ADO
    ... Look at the UpdateBatch method of the ADO recordset object. ... MVP Microsoft Access ...
    (microsoft.public.vb.database.ado)
  • oracle outer join
    ... I use ADO and set the provider is 'OraOLEDB.Oracle.1'; ... when I use outer join to get ado recordset object, The recordset can't editable, ...
    (microsoft.public.data.ado)
  • Re: Accessing multiple fields in report function
    ... The only other option would seem to be to open a recordset, ... The database already exists. ... >>> Dim Tbl As TableDef ... >>> For Each fld In Tbl.Fields ...
    (microsoft.public.access.modulesdaovba)