Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: exporting MS ACCESS tables into a CSV file

by dirac (Beadle)
on Jul 12, 2005 at 08:03 UTC ( #474201=note: print w/replies, xml ) Need Help??


in reply to exporting MS ACCESS tables into a CSV file

This is a simple example for a table Clients with fields CompanyName, ClientID, Phone in a file TestAccess.mdb.
See also Text::CSV.
use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft ActiveX Data Objects'; # Change these three variables my $database = "TestAccess.mdb"; my $table = "Clients"; my $field1 = "CompanyName"; my $field2 = "ClientID"; my $field3 = "Phone"; my $Conn = Win32::OLE->new("ADODB.Connection"); my $RS = Win32::OLE->new("ADODB.Recordset"); my $DSN = "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$database;UID=;PWD=;"; $Conn->Open($DSN); my $SQL = "SELECT $field1, $field2, $field3 FROM $table"; $RS->Open($SQL, $Conn, 1, 1); until ($RS->EOF) { my $value1 = $RS->Fields($field1)->value; my $value2 = $RS->Fields($field2)->value; my $value3 = $RS->Fields($field3)->value; print $value1,"\t",$value2,"\t",$value3,"\n"; $RS->MoveNext; } $RS->Close; $Conn->Close;

Replies are listed 'Best First'.
Re^2: exporting MS ACCESS tables into a CSV file
by chicago928 (Initiate) on Jul 12, 2005 at 08:32 UTC
    what if i don't know the table names or the fields in each table in advance? I will however easily know the filenames.
Re^2: exporting MS ACCESS tables into a CSV file
by Anonymous Monk on Apr 08, 2008 at 10:40 UTC
    Hi All, I have tries the above code but when i'm trying to access the tables and columns which contains white spaces it's giving the following error: (Can't call method "value" on an undefined value) Please help

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://474201]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2023-02-06 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (36 votes). Check out past polls.

    Notices?