Murray Brown
asked on
Access VBA/VSTO get column data types for a table
Hi
I have a VB.net project where I need to find the Access data types for any given table.
So far, I am using the following VB.net code, which pulls schema information into a grid,
where a column called DATA_TYPE holds an integer value relating to data types. This isn't ideal. Surely there is a way to get the data types of the columns via the primary interop assemblies? Does anyone have a better way. An Access VBA example would help
Sub Fill_Schema_DGV(ByVal oConnectionString As String)
Try
Dim connection As New OleDbConnection(oConnectio nString)
connection.Open()
Dim mySchema As DataTable = TryCast(connection, OleDbConnection).GetOleDbS chemaTable (OleDbSche maGuid.Col umns, New [Object]() {Nothing, Nothing, Nothing})
'Dim SchemaColumn = connection.GetOleDbSchemaT able(schem a:=OleDbSc hemaGuid.C olumns, _
'restrictions:=New Object() {Nothing, Nothing, oTableName, Nothing})
'Dim DataRowArray() As DataRow = SchemaColumn.Select(Nothin g, "ORDINAL_POSITION", DataViewRowState.CurrentRo ws)
'Me.DataGridView1.DataSour ce = mySchema
mySchema.DefaultView.Sort = "Ordinal_Position"
Me.DataGridView1.DataSourc e = mySchema.DefaultView
Catch ex As Exception
MsgBox("Failed to retrieve Access database schema information ! " & ex.Message)
End Try
End Sub
I have a VB.net project where I need to find the Access data types for any given table.
So far, I am using the following VB.net code, which pulls schema information into a grid,
where a column called DATA_TYPE holds an integer value relating to data types. This isn't ideal. Surely there is a way to get the data types of the columns via the primary interop assemblies? Does anyone have a better way. An Access VBA example would help
Sub Fill_Schema_DGV(ByVal oConnectionString As String)
Try
Dim connection As New OleDbConnection(oConnectio
connection.Open()
Dim mySchema As DataTable = TryCast(connection, OleDbConnection).GetOleDbS
'Dim SchemaColumn = connection.GetOleDbSchemaT
'restrictions:=New Object() {Nothing, Nothing, oTableName, Nothing})
'Dim DataRowArray() As DataRow = SchemaColumn.Select(Nothin
'Me.DataGridView1.DataSour
mySchema.DefaultView.Sort = "Ordinal_Position"
Me.DataGridView1.DataSourc
Catch ex As Exception
MsgBox("Failed to retrieve Access database schema information ! " & ex.Message)
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER