Field Order using ADOX .columns Help!

Field Order using ADOX .columns Help!

Post by Grif » Tue, 24 Apr 2001 17:18:45



I've got a bit of a problem.

I want to retrieve the names of the fields in a table. ( Simple ).

To do this I'm using ADOX.

I've got something like this.

Public Function GetFieldName(intFieldNo As Integer) As String

    GetFieldName = ocat.Tables(mstrTableName).Columns(intFieldNo).Name

End Function

The problems is the fields are returned in Alphabetical order!!!!!
Doh.

I want them in the same order as they are set in the DB.

Anyone got any ideas.????

Griff

 
 
 

Field Order using ADOX .columns Help!

Post by Grif » Tue, 24 Apr 2001 17:39:40


PS.

ocat is a  ADOX.Catalog

 
 
 

Field Order using ADOX .columns Help!

Post by Richa » Tue, 24 Apr 2001 19:04:29


On Mon, 23 Apr 2001 08:18:45 GMT, Griff


>I've got a bit of a problem.

>I want to retrieve the names of the fields in a table. ( Simple ).

>To do this I'm using ADOX.

>I've got something like this.

>Public Function GetFieldName(intFieldNo As Integer) As String

>    GetFieldName = ocat.Tables(mstrTableName).Columns(intFieldNo).Name

>End Function

>The problems is the fields are returned in Alphabetical order!!!!!
>Doh.

I am not sure you can get the order from ADOX. You would expect you
should, but I could not find it.

You can get the order with the OpenSchema method, ie

cn is an open connection, rs an unassigned recordset

Set rs = cn.OpenSchema(adSchemaColumns, Array(Empty, Empty, _
              "mstrTableName"))

FieldlOrderNumber = rs!ORDINAL_POSITION
FieldName$  = rs!COLUMN_NAME

Use the locals window during a break to see the other  26 field in
this recordset.

- Show quoted text -

Quote:

>I want them in the same order as they are set in the DB.

>Anyone got any ideas.????

>Griff

 
 
 

Field Order using ADOX .columns Help!

Post by Richa » Tue, 24 Apr 2001 19:47:25


I made a typing error


>On Mon, 23 Apr 2001 08:18:45 GMT, Griff

>>I've got a bit of a problem.

>>I want to retrieve the names of the fields in a table. ( Simple ).

>>To do this I'm using ADOX.

>>I've got something like this.

>>Public Function GetFieldName(intFieldNo As Integer) As String

>>    GetFieldName = ocat.Tables(mstrTableName).Columns(intFieldNo).Name

>>End Function

>>The problems is the fields are returned in Alphabetical order!!!!!
>>Doh.

>I am not sure you can get the order from ADOX. You would expect you
>should, but I could not find it.

>You can get the order with the OpenSchema method, ie

>cn is an open connection, rs an unassigned recordset

>Set rs = cn.OpenSchema(adSchemaColumns, Array(Empty, Empty, _
>              "mstrTableName"))

This line should be

Set rs = cn.OpenSchema(adSchemaColumns, Array(Empty, Empty, _
              mstrTableName))

- Show quoted text -

Quote:

>FieldlOrderNumber = rs!ORDINAL_POSITION
>FieldName$  = rs!COLUMN_NAME

>Use the locals window during a break to see the other  26 field in
>this recordset.

>>I want them in the same order as they are set in the DB.

>>Anyone got any ideas.????

>>Griff

 
 
 

Field Order using ADOX .columns Help!

Post by Grif » Wed, 25 Apr 2001 20:00:47


Thanks for the help.

 
 
 

Field Order using ADOX .columns Help!

Post by Nisha » Tue, 26 Jun 2001 20:21:32


I have a similar problem.
I'm making a copy of a database including the tables and
columns using ADOX.

However, in the new copied database, instead of the
columns appearing in the same order as they were copied,
they are sorted in alphabetical order which I don't want.

Can anyone help?

Nisha S

Quote:>-----Original Message-----
>I've got a bit of a problem.

>I want to retrieve the names of the fields in a table. (
Simple ).

>To do this I'm using ADOX.

>I've got something like this.

>Public Function GetFieldName(intFieldNo As Integer) As
String

>    GetFieldName = ocat.Tables(mstrTableName).Columns
(intFieldNo).Name

>End Function

>The problems is the fields are returned in Alphabetical
order!!!!!
>Doh.

>I want them in the same order as they are set in the DB.

>Anyone got any ideas.????

>Griff

>.

 
 
 

1. Define Column Order When Creating Table Using ADOX

I'm using ADOX to create a table on the fly.  I'm using the ODODB.catalog
object and the columns.append syntax to add the fields to the database.

This works OK only trouble is they always get created in alphabetical order
and I want then in the order in which I create them.

I'm using the OLEDB 3.51 Access driver to access an Access 97 database
(phew!).   Any pointers?

2. Jet and DBF Files

3. Precision is Invalid when Adding Column to table using adox (columns.append)

4. Creating MDB, then formating a field (date) to Long Time or Medium Time ???

5. ADOX Column order

6. Need SQL/WINNT Expert Advice

7. Columns name in alphab.order with ADOX

8. Foxpro connection not released

9. ADOX Column order

10. Columns name in alphab.order with ADOX

11. ADOX: Column Order and Properties

12. Columns name in alphab.order with ADOX

13. ADOX: Column Object: Need Help: Making Column Identity