How to Write a Text File Into a Database Table Using Visual Basic

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Write a Text File Into a Database Table Using Visual Basic
Write a text file to an Access database using Visual Basic. (text of the bible image by Alexey Klementiev from

Microsoft Visual Basic (VB) is a programming language that is easy to learn and use. VB is used to develop user-friendly Windows applications. One common task in the programming world is to move file information from one location to another. You can easily save information in a text file to a Microsoft Access database table using Microsoft OLE DB. Access is a relational database application included in the Microsoft Office suite.

Skill level:

Other People Are Reading

Things you need

  • Microsoft Office Access 2003
  • Microsoft Notepad
  • Microsoft Visual Basic 2010 Express

Show MoreHide


  1. 1

    Open "Notepad" and type "NAME, AGE, CITY" in the first line.

    Type "JOHN, 25, WATAUGA" in the second line.

    Save the file to "C:\" as "myTextFile.txt".

  2. 2

    Open Microsoft Access and create a new database. Save your database to "C:\" as "test.mdb".

    Start Microsoft Visual Basic 2010 Express, select the "File" menu and click "New Project...". Click on "Windows Forms Application" and select "OK."

  3. 3

    Double-click "Button" on the "Toolbox" menu to add a new button to "Form1." Double-click "Button1" to start writing your code under "Form1.vb."

  4. 4

    Type "Imports System.Data.OleDb" in the first line of "Form1.vb."

  5. 5

    Type the following inside the "Button1_Click" subroutine to define your connection and command:

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

        Dim oledbCommand As New OleDbCommand("SELECT * INTO [myTextFile] FROM [Text;Database=C:\;Hdr=Yes].[myTextfile.txt]", oledbConn)
  6. 6

    Type the following to open the connection and execute the command then close the connection:




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

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

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