How to Insert Data Into Access Using VB.Net

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Insert Data Into Access Using VB.Net
Insert data into a table in Access using Visual Basic.NET. (binary code digital tunnel background image by Stasys Eidiejus from Fotolia.com)

Knowing how to insert data into Access using Visual Basic.NET can save you time when you need to add multiple records manually. Microsoft Access is a relational database application included in the Microsoft Office suite. Visual Basic.NET is a programming language developed by Microsoft that is relatively easy to learn and use. Write VB.NET code to create a new table in Access and insert data into the new table.

Skill level:
Easy

Other People Are Reading

Instructions

  1. 1

    Start Microsoft Access and select "Blank Database." Name the database "Test" and click "Create."

  2. 2

    Start Microsoft Visual Basic 2010 Express, select the "File" menu and select "New Project." Click "Windows Forms Application" and select "OK." Select "Toolbox" on the left pane and double-click "Button" to add a new button to "Form1."

  3. 3

    Double-click "Button1" to open the "Form1.vb" module. Type the following in the first line of the module:

    Imports System.Data.OleDb

  4. 4

    Type the following to declare your variables inside "Private Sub Button1_Click:"

    Dim my Connection As OleDbConnection

    Dim my Command As OleDbCommand

    Dim mySQLString As String

  5. 5

    Type the following to create and open a connection to your Access database:

    my Connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test.mdb;")

    myConnection.Open()

    Edit "Source" and type the path where you saved your "Test" database.

  6. 6

    Type the following to create the "myTable" Access table:

    mySQLString = "CREATE TABLE my Table (FIRST_NAME TEXT, LAST_NAME TEXT)"

    my Command = New OleDbCommand(mySQLString, my Connection)

    myCommand.ExecuteNonQuery()

  7. 7

    Type the following to add a new record of data to the "myTable" table:

    mySQLString = "INSERT INTO my Table VALUES('JOHN','SMITH')"

    my Command = New OleDbCommand(mySQLString, my Connection)

    myCommand.ExecuteNonQuery()

    Press "F5" to run your program and click "Button1" to execute the code.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.