Table Properties

  • Thread starter Thread starter Dundappa
  • Start date Start date
D

Dundappa

hi,
I want to access the table properties (Let us say primary key of a
table) through ADO.net, connected to MSAccess table. Any help regarding this
will be appreciated

thanks
-dunds
 
Look at DataAdapter MissingSchemaAction or FillSchema. Basically, you need
to build the schema yourself or let the db return one for you.
 
¤ hi,
¤ I want to access the table properties (Let us say primary key of a
¤ table) through ADO.net, connected to MSAccess table. Any help regarding this
¤ will be appreciated
¤

You can use GetOleDbSchemaTable:

Sub ListTableSchema()

Dim AccessConnection As New System.Data.OleDb.OleDbConnection()
Dim SchemaTable As DataTable

AccessConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\My Documents\db1.mdb"
AccessConnection.Open()

'Retrieve schema information about Table1 Columns.
'SchemaTable =
AccessConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, _
' New Object() {Nothing, Nothing, "Table1"})

'Retrieve schema information about Table1 Primary Keys.
SchemaTable =
AccessConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Primary_Keys, _
New Object() {Nothing, Nothing, "Table1"})

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

DataGrid1.DataSource = SchemaTable

AccessConnection.Close()

End Sub


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top