Solved

How to import text file into MS Access database

Posted on 2007-11-27
2
2,115 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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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