Murray Brown
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.Th isAddIn.oR IGHT.lblCo nnectionSt ring.Text)
cn.Open()
'Retrieve the tables from the schema.
Dim SchemaTable As DataTable = _
cn.GetOleDbSchemaTable(sch ema:=Data. OleDb.OleD bSchemaGui d.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:=Co untTables) !TABLE_NAM E.ToString ()
'Get the column names in the table.
Dim SchemaColumn = cn.GetOleDbSchemaTable(sch ema:=OleDb SchemaGuid .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:=C ountColumn s)!COLUMN_ NAME.ToStr ing
oColumnType = SchemaColumn.Rows(index:=C ountColumn s)!COLUMN_ TYPE.ToStr ing 'XXXXX
Next
Next CountTables
cn.Close()
cn.Dispose()
cn = Nothing
Catch ex As Exception
MsgBox ex.Message)
Finally
'cn = Nothing
End Try
End Sub
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.Th
cn.Open()
'Retrieve the tables from the schema.
Dim SchemaTable As DataTable = _
cn.GetOleDbSchemaTable(sch
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:=Co
'Get the column names in the table.
Dim SchemaColumn = cn.GetOleDbSchemaTable(sch
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:=C
oColumnType = SchemaColumn.Rows(index:=C
Next
Next CountTables
cn.Close()
cn.Dispose()
cn = Nothing
Catch ex As Exception
MsgBox ex.Message)
Finally
'cn = Nothing
End Try
End Sub
What's the error?
ASKER
COLUMN_TYPE does not belong to table Columns
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much