Schema Info

G

Guest

Does anyone know how to get columns' properties (just like what sp_columns gives you) by using the Oledb get schema method of the ado.net connection object

Thanks.
 
P

Paul Clement

¤ Does anyone know how to get columns' properties (just like what sp_columns gives you) by using the Oledb get schema method of the ado.net connection object?

You can use GetOleDbSchemaTable:

Sub ListDatabaseSchema()

Dim DatabaseConnection As New System.Data.OleDb.OleDbConnection
Dim SchemaTable As DataTable

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

DatabaseConnection.Open()

SchemaTable =
DatabaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, _
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

DatabaseConnection.Close()


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

Paul Clement

¤ how do you get the column properties? the width, data types, etc. ?

Did you run the code and check the DataGrid? The properties for each column should be displayed.

The DATA_TYPE property values corresponds to the System.Data.OleDb.OleDbType enum.


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top