By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,903 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,903 IT Pros & Developers. It's quick & easy.

Reading from ms Access

P: 1
I am new to using perl and am trying to read data from an ms access database.
I have opened the database and can extract data from a table with limited success.
What I have done so far is open the database using
use Win32::ODBC;
etc

Then I have the following code:
Expand|Select|Wrap|Line Numbers
  1. #while ($db->FetchRow())  { 
  2.   while ($i<10) {
  3.   $db->FetchRow() ;
  4.     my %Data = $db->DataHash();
  5.     print $i," ",$Data{Au_plot},"," ;
  6.     print $Data{Cu},"," ;
  7.     print $Data{Zn},"," ;
  8.     print $Data{Pb};
  9.   $i++;
  10.   print "\n";
  11. }
  12.  
This works ok as the first 10 rows are extracted from the table I have selected.
But when I use
Expand|Select|Wrap|Line Numbers
  1. while ($db->FetchRow())  { 
  2.  
  3. instead of
  4. while ($i<10) {
  5.  
the first record extracted is number 2 in the table and from then on only every second record is extracted form the table.

Could someone tell me what is going on please?
Thanks
Chris
Dec 11 '08 #1
Share this Question
Share on Google+
1 Reply


numberwhun
Expert Mod 2.5K+
P: 3,503
@new2perl
First, please use code tags around any code you provide in the forums. They are required and need to be added if you forget them.

As far as your questions goes, I don't use MS Access. I like to stick to MySQL myself, but in Perl, when you access a database, you typically use the DBI module in conjunction with a DBD (database driver module). For instance, you always "use DBI", but if I am using MySQL, I would also include "use DBD::mysql" as well so that DBI knew how to interact with my database of choice.

In your case, its MS Access and unfortunately I don't think there is specifically a driver for it, but I know that I have read about people using DBD::ODBC for the interaction. You could give it a try and see if it works for you. I know MS Access is mentioned on the page.

In addition, you may want to search Google as I am sure they have a plethora of information on the topic of using Perl with MS Access.

Regards,

Jeff
Dec 11 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.