Solved

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

Posted on 2013-01-16
4
507 Views
Last Modified: 2013-01-16
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
0
Comment
Question by:murbro
  • 2
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38784418
What's the error?
0
 

Author Comment

by:murbro
ID: 38784452
COLUMN_TYPE does not belong to table Columns
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38784511
0
 

Author Closing Comment

by:murbro
ID: 38785873
Thanks very much
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question