Solved

How to import text file into MS Access database

Posted on 2007-11-27
2
2,113 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net Tranfer data between to VB.Net apps 8 44
vb.net 1 month apart 11 39
Help with error in Query 2 39
Cannot kill Excel from taskmgr after Excel Export in VB 2014 6 36
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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