468,101 Members | 1,338 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,101 developers. It's quick & easy.

How to get Table Properties??? GetSchema???

Hello All,

I am wanting to make a small utility that allows the user (me) to select a local database (currently Access 2000), build a list of non-system tables,
then select a table which will then populate a datagridview with the column name, default, null, if primary key, etc......

I've seen the code for obtaining this info before, but can't rememeber where. Can anyone help? Using vb.net 2005.

The code below allows the user to select a db file and adds each non-system table to a combo box. After browsing thru the combo box, I need the code
to retrieve into a dataset all the columns with properties of the selected table.

Thanks,

Hexman

I started with this to get the table:
================================================== ==========
Dim dbPath As String = "C:\"
Dim dbFileName As String = "Test.mdb"

Dim ofdDataBases As New OpenFileDialog()
ofdDataBases.Title = "Display Database Table Structure"
ofdDataBases.InitialDirectory = "C:\"
ofdDataBases.Filter = "All files (*.*)|*.*|MDB files (*.mdb)|*.mdb"
ofdDataBases.FilterIndex = 2
ofdDataBases.RestoreDirectory = True

If ofdDataBases.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
tbDatabase.Text = ofdDataBases.FileName
tbPrefix.Text = ""
cboTables.Items.Clear()

Dim cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & dbPath & dbFileName & ";")
cn.Open()
Dim dt As New DataTable
Dim dr As DataRow
dt = cn.GetSchema("Tables")
For Each dr In dt.Rows
If dr.Item(3) = "TABLE" Then 'Only select user tables, not system tables
cboxTables.Items.Add(dr.Item(2))
End If
Next

cn.Close()
End If

================================================== ==========
Jan 17 '07 #1
0 5397

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by nathan.gomez | last post: by
1 post views Thread by Chris | last post: by
46 posts views Thread by John | last post: by
3 posts views Thread by Markus Weber \(Megalith GmbH\) | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.