Hi,
I'm new at this game, and tearing my hair out...
I've successfully got some Perl that queries a database without a
predicate (no WHERE statement). When I attempt to retrieve specific
data, I get either no results returned or errors ;
DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access Driver]
Too few parameters. Expected 1. (SQL-07002)(DBD: st_execute/SQLExecute
err=-1) at database connection2.pl line 16.
Could not execute SQL statement, maybe invalid? at database
connection2.pl line 16
My perl code looks like this;
use DBI;
use warnings;
#open connection to Access database
$dbh = DBI->connect('dbi:ODBC:Deliveries');
#construct SQL statement
$sqlstatement=
"SELECT DestinationAddress,CustomerContactNumber
FROM DeliveryScheule
WHERE DeliveryID = \"6636\"\n";
print "SQL:"."\n".$sqlstatement."\n";
#prepare and execute SQL statement
$sth = $dbh->prepare($sqlstatement);
$sth->execute ||
die "Could not execute SQL statement, maybe invalid?";
#Put the results in an array
[EMAIL PROTECTED]>fetchrow_array;
($DestinationAddress,$CustomerContactNumber)=$sth->fetchrow_array;
#output database results
# while (@row=$sth->fetchrow_array)
# { print "@row\n" }
# $sth->dump_results;
while ($row=$sth->fetchrow_hashref)
{print "Address: $row->{DestinationAddress}\t
Phone Number: $row->{CustomerContactNumber}\n"};
print $sth->rows."\n";
If I play around with the SQL statement construction - by using escaped
speach marks - I can get rid of the error, but get no results returned.
When I take my printed SQL statement (from the print
"SQL:"."\n".$sqlstatement."\n"; line) then Copy and Paste into MS Access
as a SQL query - all is fine - I get my expected result. What's going on?
Thanks in advance...
Jez
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>