Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to import text file into MS Access database

Posted on 2007-11-27
2
Medium Priority
?
2,123 Views
Last Modified: 2012-05-05
I'm trying to import a comma delimited text file into a MS Access database with vb.net. The text file I want to import is named ACD5.txt. The database name is Support_Stats.mdb with one table named Calls. I'm trying the code below, but I'm getting the An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll error on the cmd.ExecuteNonQuery line. Please see the attached code.
Dim connect As String
        connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=U:\Manager\Support Team Measurement\Stats_Database\Support_Stats.mdb"
        Dim conn As New OleDbConnection(connect)
        Dim path As String = "U:\Manager\Support Team Measurement\Stats_Database\Support_Stats.mdb"
        Dim query As String = "INSERT INTO Calls (Week Starting, Inbound ACD Calls, Avg Inbound ACD Time) SELECT Week Starting, Inbound ACD Calls, Avg Inbound ACD Time FROM [Text;DATABASE=" & path & ";].[ACD5.txt]"
        Dim cmd As OleDbCommand = New OleDbCommand(query, conn)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()

Open in new window

0
Comment
Question by:myester
2 Comments
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 2000 total points
ID: 20362036
Begin by putting [] around the field names. You can't have spaces in field names and expect them to behave well. (It won't take long before this is such a pain that you train yourself out of the habit of using spaces)
   Dim query As String = "INSERT INTO Calls ([Week Starting], [Inbound ACD Calls], [Avg Inbound ACD Time]) SELECT [Week Starting], [Inbound ACD Calls], [Avg Inbound ACD Time] FROM [Text;DATABASE=" & path & ";].[ACD5.txt]"
    

Open in new window

0
 

Author Closing Comment

by:myester
ID: 31411310
Chaosian, that works great. Thanks for your help. I normally wouldn't use spaces but that's how it is in the text file so I thought the code needed to match that. I will remember to not use spaces. Thanks again.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question