PDA

Click to See Complete Forum and Search --> : Table and Column references in Vb


lenin
Oct 18th, 2000, 08:49 AM
Sorry, I have posted this is general and got no response.

Hi,
I want to find out the Table and Column names in an Access database, referenced via a DSN. If the table is a certain name then I want to write out the columns, however I find when I do this that there are additional "column" names provided which are not part of my definition. Also I have no views / queries in the database so this isn't the source also.

e.g. repl_test1 table
ID AutoNumber
Number Number
On_Hold Yes/No
Date_Start Date/Time

with the following source:


Private Sub Form_Load()

Dim lc_connection As ADODB.Connection
Dim lrs_tables As ADODB.Recordset
Dim lrs_columns As ADODB.Recordset

Dim ls_Connection As String

Set lc_connection = New ADODB.Connection
lc_connection.Open "DSN=TONY2"

Set lrs_tables = lc_connection.OpenSchema(adSchemaTables)

Do Until lrs_tables.EOF
If lrs_tables!table_name = "repl_test1" Then
Set lrs_columns = lc_connection.OpenSchema(adSchemaColumns)
Do Until lrs_columns.EOF
Debug.Print "Column Name: " & lrs_columns!COLUMN_NAME
lrs_columns.MoveNext
Loop
End If
lrs_tables.MoveNext
Loop

End Sub


Produces:
Column Name: Data
Column Name: ID
Column Name: ID
Column Name: Number
Column Name: on_hold
Column Name: date_start


As you can see two extra columns. If someone could answer:

1. Where do these come from, and
2. how do I get rid of them

Any help appreciated.

MrGTI
Oct 18th, 2000, 09:28 AM
I believe those are Microsoft created objects of some sort. Maybe Index's or something.

I have a sample project on my harddrive called "FindTableFieldNames" that acurately gets the names of tables and fields from a database. I assembled it from code i have collected.

Email me at home if you want it.