How to Get MS Access Table Fields or Columns in VB.Net

0
106

This tutorial is all about How to Get MS Access Table Fields or Columns in VB.Net. In this Tutorial you will learn How to Get MS Access Table Fields or Columns in VB.Net. So let’s get Started:

  • First is that you have created a MS Access Database file and it should have been put in to the Bin Folder of your Visual Basic Project.
  • Open the Visual Basic, Select File on the menu, then click New and create a new project.

  • Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK

  • After that, design your form like this just like what I’ve shown you below.
    Add a Listbox and a Button from the Toolbox.
  • Add this following Codes before the Public Class Form1 Line.
    1. Imports System.Data.OleDb
  • Next, Add this following Declarations below the Public Class Form1 Line.
    1. Dim provider As String
    2. Dim dataFile As String
    3. Dim connString As String
    4. Dim myConnection As OleDbConnection = New OleDbConnection
  • Finally, add this code to the Button.
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
    3. dataFile = "C:\Users\Clive\Documents\Visual Studio 2008\clive projects\TableRecordsinCombobox\TableRecordsinCombobox\bin\Debug\Datalist.accdb"
    4. connString = provider & dataFile
    5. myConnection.ConnectionString = connString
    6. myConnection.Open()
    7. Try
    8. Dim Rest() As String = {Nothing, Nothing, "tblname", Nothing}
    9. Dim columns As String = "Columns"
    10. Dim dt As DataTable = myConnection.GetSchema(columns, Rest)
    11. For Each row As DataRow In dt.Rows
    12. ListBox1.Items.Add(row.Item("COLUMN_NAME").ToString)
    13. NextmyConnection.Close()
    14. Catch ex As Exception
    15. End Try
    16. End Sub

Click F5 to run the program.

If you have any comments or suggestions about on How to Get MS Access Table Fields or Columns in VB.Net, please feel free to contact our webpage.

Download How to Get MS Access Table Fields or Columns in VB.Net Here

Other Articles Readers might read:

 

 

 

 

Facebook Comments
(Visited 131 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here