Fields in Access database returned in alphabetical order

  • Thread starter Thread starter Julian
  • Start date Start date
J

Julian

I'm using the following VB.Net code to retreive the field names of a table
in an Access db:

Dim NewField As ADOX.Column
Dim tblField As ADOX.Column

For Each tblField In adocat.Tables("tblData").Columns


The fields are returned in alphabetical order! I want to have the fields
returned in the order they were created. Can this be done?

-Julian
 
Julian said:
I'm using the following VB.Net code to retreive the field names of a
table in an Access db:

Dim NewField As ADOX.Column
Dim tblField As ADOX.Column

For Each tblField In adocat.Tables("tblData").Columns


The fields are returned in alphabetical order! I want to have the
fields returned in the order they were created. Can this be done?

-Julian



It is not available in ADOX. Use DAO for native Jet support. See the
Ordinalposition property of the Field object. The DAO docu also says that
two fields can have the same ordinal position. More information:
http://msdn.microsoft.com/archive/d...e/en-us/office97/html/output/F1/D2/S5A2D1.asp


Armin
 
Armin said:
It is not available in ADOX. Use DAO for native Jet support. See the
Ordinalposition property of the Field object. The DAO docu also says
that two fields can have the same ordinal position. More information:
http://msdn.microsoft.com/archive/d...e/en-us/office97/html/output/F1/D2/S5A2D1.asp



Armin

You can get it in ADO which is the .net way of doing things. There is a
function on the connection or command object called gettableschema that
will get you the info you want.

Chris
 
Chris said:
You can get it in ADO which is the .net way of doing things. There
is a function on the connection or command object called
gettableschema that will get you the info you want.


I thought ADOX is even closer to DAO than ADO.Net. Therefore I did
not even think of doing it in ADO.Net. But your probably right.


Armin
 
Julian said:
How do you use DAO in VB.Net?


Set a reference to "Microsoft Data Access Objects". But you should probably
better have a look at Chris' answer.

See also: System.Data.OleDb.OleDbConnection.GetOleDbSchemaTable

and

http://msdn.microsoft.com/library/en-us/oledb/htm/oledbcolumns_rowset.asp
Column "ORDINAL_POSITION"

http://msdn.microsoft.com/library/en-us/oledb/htm/oledbprovjet_overview.asp
especially
http://msdn.microsoft.com/library/en-us/oledb/htm/oledbprovjet_supported_schema_rowsets.asp





Armin
 
Back
Top