ketema has asked for the wisdom of the Perl Monks concerning the following question:

I have a question for the mighty monks...I can't figure out why recordsets I create with the Win32::OLE module, can't use the filter property.
use strict; use Win32::OLE; use Win32::OLE::Const; use Win32::OLE::Variant; my $Constname = "Microsoft ActiveX Data Objects 2\\.0 Library"; my $ado_consts = Win32::OLE::Const->Load($Constname); my $database = "somedb"; my $hostname = "somehost"; my $port = "someport"; my $user = "user"; my $password = "pass"; my $conn = Win32::OLE->new("ADODB.Connection"); $conn->{"ConnectionString"} = "Provider=SQLOLEDB.1;User ID=$user;Passw +ord=$pass;Initial Catalog=$database;Data Source=$hostname"; $conn->open(); my $recordSet = Win32::OLE->new("ADODB.RecordSet"); my $sql = "select * from table"; $recordSet->{"ActiveConnection"} = $conn; $recordSet->{"CursorLocation"} = 3; $recordSet->{"CursorType"} = 1; $recordSet->{"LockType"} = 3; $recordSet->open($sql); print $recordSet->Supports($ado_consts->{"adBookmark"})."\n"; my $myFilter = "Where Clause without the where"; $recordSer->Filter => $myFilter while (! $recordSet->EOF) { print $recordSet->Fields(0)->value."\n"; $recordSet->MoveNext; } print "\n";
now the supports function returns a 1 for 0x2000 or adBookmark so I should Be able to use the Filter Property, and i get an error instead telling me that the Filter Property doesn't exist. To be exact i get:
Win32::OLE(0.1403) error 0x8002000e: "Invalid number of parameters" in METHOD/PROPERTYGET "Item" at (eval 409)[e:/PROGRA~1/ACTIVE~1//p +erl5db.pl: 1556] line 2
And i have also noticed that the Properties->Item value is undef, even though the Properties->Count values is 103. Whatever Wisdom the monks Give Would be Greatly Appreciated. Thanks In advance, ketema

Replies are listed 'Best First'.
Re: OLE ADO & Win32
by spoulson (Beadle) on Aug 10, 2004 at 13:20 UTC
    The problem is that the Filter property... is a property, not a method.
    $recordSet->Filter => $myFilter;
    should be:
    $recordSet->{Filter} = $myFilter;
    Also, it appears you're using the => operator incorrectly and you fatfingered $recordSet as $recordSer in your code.
      I know its a property and I apologize for my typing. I have tried it both ways $recordSet->{'Filter'} $recordSet->Filter(); I tried everything, and I get the same error every time. I finally just converted to DBI and hashes. works great, but I still would liket o know why the OLE didn't work.
        I'm not sure if this'll apply to you; I know that in some cases with Sort, I need to do a MoveFirst to ensure I'm at the top. You're probably better off with DBI anyway. ADO is so slow anyway.