Software >> Development >> API >> ADO >> Perl >> How to define a subroutine to extract a database column

Example :- sub GetDBColumn() { use OLE; my $colname = shift; my $table = shift; my $accessfile = shift; my $sqlquery = "select $colname from $table"; my $CursortType = 3; my $LockType = 1; my @outcolumn; my $Conn = CreateObject OLE "ADODB.Connection"; my $RS = CreateObject OLE "ADODB.Recordset"; $Conn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=$accessfile"); $RS = $Conn->Execute("$sqlquery",$CursorType,$LockType); if(!$RS) { $Errors = $Conn->Errors(); print "Errors:\n"; foreach $error (keys %$Errors) { print $error->{Description}, "\n"; } die; } while ( !$RS->EOF ) { $coldata = $RS->{Fields}->{"$colname"}->{Value}; print "$coldata\n"; push @outcolumn, $coldata; $RS->MoveNext; } $RS->Close; $Conn->Close; return @outcolumn; }