?
Solved

Microsoft Text Driver with ADO to import CSV files

Posted on 2006-05-08
3
Medium Priority
?
1,955 Views
Last Modified: 2010-05-19
Hi,

I am trying to import CSV files with the microsoft text driver.

I am using TAdoConnection and TAdoTable.

The following code works fine:

// start
Connection.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\;Extended Properties="text;HDR=No;FMT=Delimited";Persist Security Info=False';
Table.TableName:='BLAH-BLAH.CSV';
Table.Open;
// end

except when I try to use a file that is not in "C:\". My files are in a nested directory such as "C:\up\Br\08052006-110551\". If I change my datasource in the connection string to "C:\up\Br\08052006-110551\" then I get a message saying "syntax error in from clause"

How do I sort this out?

Thanks:)
0
Comment
Question by:trnxp
1 Comment
 
LVL 4

Accepted Solution

by:
JDSkinner earned 1600 total points
ID: 16704614
Hi
I tried to emulate your setup using the same path and targeted a csv file.
I modified the first line of each csv file to indicate which drive it was on.

When initially started the connection string pointed to the D drive, this worked fine.
I then used the following piece of code to redirect the table to the alternative location.

procedure TForm1.Button1Click(Sender: TObject);
begin
  strPath:= 'Provider=Microsoft.Jet.OLEDB.4.0;Password=""'
  + ';User ID=admin;Data Source=C:\Up\Br\08052006-110551'
  + ';Mode=Share Deny None;Extended Properties="text;HDR=No;FMT=Delimited"'
  + ';Jet OLEDB:System database="";Jet OLEDB:Registry Path=""'
  + ';Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=96;'
  + 'Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2'
  + ';Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=""'
  + ';Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False'
  + ';Jet OLEDB:Do not Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;'
  + 'Jet OLEDB:SFP=False';

    ADOConnection.Close;
    ADOConnection.ConnectionString := strPath;
    ADOConnection.Connected:= true;
    ADOTable1.Active:= true;
end;

This worked Ok.

I would not use this as a permanent solution.

Have a look at the following link
Creating a UDL file programmatically
http://www.efg2.com/Lab/Library/Delphi/ADO/UDL/index.html#Programmatically

That may work as well if you set
DatasourceName:= 'Provider=Microsoft.Jet.OLEDB.4.0;Password=""'
  + ';User ID=admin;Data Source=C:\Up\Br\08052006-110551'
  + ';Mode=Share Deny None;Extended Properties="text;HDR=No;FMT=Delimited"'
  + ';Jet OLEDB:System database="";Jet OLEDB:Registry Path=""'
  + ';Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=96;'
  + 'Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2'
  + ';Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=""'
  + ';Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False'
  + ';Jet OLEDB:Do not Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;'
  + 'Jet OLEDB:SFP=False';

If you do use a UDL file make sure that its on the lookup path.

0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

616 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