Get a Database Table properties programmatically in VB.NET

This program displays you a table properties such as its column names, types, and column properties. I have used a database "mcTest.mdb" which has a table called 'Developer'. You can download this attached database and change the path of the database according to your location.
  • 7754
 

This program displays you a table properties such as its column names, types, and column properties. I have used a database "mcTest.mdb" which has a table called 'Developer'. You can download this attached database and change the path of the database according to your location.  

table-properties-in-vb.net.jpg
 

Explaination

I have used ADODataSetCommand, DataSet, DataTable, and DataColumn classes to do so. See my forthcoming tutorial on ADO.NET for more details of these classes.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strDSN As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mcTest.MDB"
Dim strSQL As String = "SELECT * FROM Developer"
' create Objects of ADOConnection and ADOCommand
Dim myConn As New OleDbConnection(strDSN)
Dim myCmd As New OleDbDataAdapter(strSQL, myConn)
myConn.Open()
Dim dtSet As New DataSet
myCmd.Fill(dtSet, "Developer")
Dim dt As DataTable = dtSet.Tables(0)
listBox1.Items.Add("Field Name DataType Unique AutoIncrement AllowNull")
listBox1.Items.Add("====================================================")
Dim
dc As DataColumn
For Each dc In dt.Columns
listBox1.Items.Add((dc.ColumnName + " , " + dc.DataType + " ," + dc.Unique + " ," + dc.AutoIncrement + " ," + dc.AllowDBNull))
Next dc
End Sub 'Form1_Load

How to Run?

  • Download source code and database zip files and unzip them.
  • Change the database path  in this string. 
    "Provider=Microsoft.JET.OLEDB.4.0;data source=C:\\Mahesh\\mcb.mdb");
  • Run the application

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.