Get table names from MSAccess Datasource

  • Thread starter Thread starter Steven Smith
  • Start date Start date
S

Steven Smith

Hello all,

I have a vb6 (not .NET) program using MS Access as the backend. As part of
an import form, I need to allow the user to select the table containing the
data to be imported. How can I populate a combo with this information?
Then, once this value is selected, how can I populate other combos with the
column names of the selected table?


Thanks,

Steven Smith
 
Thanks Ken... it wasn't quite what I needed, but it pointed me in the right
direction.
 
Somebody else was asking the same question, maybe we should extend our
sample with the schema information.
I forgot to type it complete, therefore the link was still in my clipboard.
 
¤ Hello all,
¤
¤ I have a vb6 (not .NET) program using MS Access as the backend. As part of
¤ an import form, I need to allow the user to select the table containing the
¤ data to be imported. How can I populate a combo with this information?
¤ Then, once this value is selected, how can I populate other combos with the
¤ column names of the selected table?
¤

List of Tables:

Dim DatabaseConnection As New System.Data.OleDb.OleDbConnection
Dim SchemaTable As DataTable

DatabaseConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Test Files\db1 XP.mdb"

DatabaseConnection.Open()

SchemaTable =
DatabaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, _
New Object() {Nothing, Nothing, Nothing,
Nothing})

Dim RowCount As Int32
For RowCount = 0 To SchemaTable.Rows.Count - 1
TableListCombo.Items.Add(SchemaTable.Rows(RowCount)!TABLE_NAME.ToString)
Next RowCount

DatabaseConnection.Close()

List of Columns:

Dim DatabaseConnection As New System.Data.OleDb.OleDbConnection
Dim SchemaTable As DataTable

DatabaseConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Test Files\db1 XP.mdb"

DatabaseConnection.Open()

SchemaTable =
DatabaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, _
New Object() {Nothing, Nothing, "Table1"})

Dim RowCount As Int32
For RowCount = 0 To SchemaTable.Rows.Count - 1
ColumnListCombo.Items.Add(SchemaTable.Rows(RowCount)!COLUMN_NAME.ToString)
Next RowCount

DatabaseConnection.Close()


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top