Hi,

I need help with Perl DBI.   I try to fetch the table from Microsoft access
database.
I want to return the whole table under the condition "FIELD1=A".
The following is my code.

my $db        = "C:\\Users\\yushanwa\\Desktop\\DATABASE.accdb";
my $DSN       = "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=$db";
my $table_name= 'TABLE';
my $key_field = 'KEY';
my $condition = 'FIELD1=A';
my $dbh = DBI->connect("dbi:ODBC:$DSN", {
    PrintError => 0,   ### report errors via warn(  )
    RaiseError => 1    ### report errors via die(  )
    }) or die "Can't connect to the database: $DBI::errstr\\n";

my $statement = qq{ SELECT * FROM $table_name WHERE $condition };
my $sth = $dbh ->prepare ($statement );
$sth -> execute; *<= line 43*
my $hash_ref = $sth->fetchall_hashref( $key_field );

return $hash_ref;
I got the following error:
*DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access Driver]
Too few
parameters. Expected 1. (SQL-07002) at C:/Users/yushanwa/Desktop/ABCD.pm
line 43.*
**
Could you please tell me where I did wrong? Thanks!

-Tiffany

Reply via email to