Win32::OLE ADO Table Field names

Win32::OLE ADO Table Field names

am 23.12.2007 19:15:38 von goldtech

Hi,

Given code below, I can get tables and run SQL on an ms-access db -
this works well. But, I want to get the field names per each column
of a table. I'm sure there's an ADO way of doing it. Help appreciated.
Thanks.

Question: How do I get the field names of each column of a table?

#!/usr/bin/perl

# use strict;
use Win32::OLE();
$Win32::OLE::Warn=2;

my $conn = Win32::OLE->new("ADODB.Connection");
my $db = 'C:\Folder4\usa.mdb';
$conn->Open('Provider = Microsoft.Jet.OLEDB.4.0; Data Source='.$db);
my $rs= $conn->OpenSchema(20);

$rs->MoveFirst();
while(!$rs->{EOF}){
my $tn= $rs->Fields(2)->Value;
if (grep /^$tn$/i, 'States') {
my $rowcount = $conn->Execute("SELECT COUNT(*) AS ROW_COUNT
FROM " .$tn.'"');
print "$tn : ".$rowcount->Fields('ROW_COUNT')->Value."\n";
}
$rs->MoveNext;
}

__END__

states : 51
DC included.

Re: Win32::OLE ADO Table Field names

am 24.12.2007 04:31:27 von unknown

Post removed (X-No-Archive: yes)

Re: Win32::OLE ADO Table Field names

am 25.12.2007 21:40:01 von goldtech

Got it finally:

....
$oRS = Win32::OLE->new("ADODB.Recordset");
$oRS->{'ActiveConnection'} = $conn;
$oRS->Open('States'); # "States" is the table name
$zztop=$oRS->Fields->Count;
$who =$oRS->Fields->Item(2)->Name;
print $zztop.' '.$who.' ';
....

:^)