Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net Error in code to get the Access column type

Hi I am using the following code to get the Access column types for all tables.
It all works except for the line 'XXXXX
What should I use at this line to get the column type

    Sub Get_Access_Schema_Info()

        Try
            Dim oColumnName As String
            Dim oColumnType As String

            Dim cn As New OleDbConnection(Globals.ThisAddIn.oRIGHT.lblConnectionString.Text)
            cn.Open()

            'Retrieve the tables from the schema.
            Dim SchemaTable As DataTable = _
            cn.GetOleDbSchemaTable(schema:=Data.OleDb.OleDbSchemaGuid.Tables, _
            restrictions:=New Object() {Nothing, Nothing, Nothing, "Table"})

            Dim oIndex As Integer = -1

            For CountTables As Integer = 0 To SchemaTable.Rows.Count - 1

                oIndex = oIndex + 1
                'Get the table name.
                Dim TableName As String = SchemaTable.Rows(index:=CountTables)!TABLE_NAME.ToString()

                'Get the column names in the table.
                Dim SchemaColumn = cn.GetOleDbSchemaTable(schema:=OleDbSchemaGuid.Columns, _
                restrictions:=New Object() {Nothing, Nothing, TableName, Nothing})


                'Get each column name

                For CountColumns As Integer = 0 To SchemaColumn.Rows.Count - 1

                    oIndex = oIndex + 1

                    oColumnName = SchemaColumn.Rows(index:=CountColumns)!COLUMN_NAME.ToString
                    oColumnType = SchemaColumn.Rows(index:=CountColumns)!COLUMN_TYPE.ToString  'XXXXX

                Next

            Next CountTables

            cn.Close()

            cn.Dispose()

            cn = Nothing

        Catch ex As Exception
            MsgBox ex.Message)
        Finally
            'cn = Nothing
        End Try

    End Sub
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

What's the error?
Avatar of Murray Brown

ASKER

COLUMN_TYPE does not belong to table Columns
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much