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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|