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
================================================== ==========