Thanks much, use is what I missed, now I went further and encountered another problem, I use Recordset to get table values, but program is terminated at $rs->RecordCount.
my $rs = Win32::OLE->new('ADODB.Recordset');
$rs->Open("Select * from $SQLTABLE", $conn);
if ($rs->RecordCount > 0) {...}
Can you point out where might be wrong?
-- PC
| [reply] [Watch: Dir/Any] |
You might want to try posting your code inside <code> </code> tags. It'll look like this:
$rs->RecordCount. my $rs = Win32::OLE->new('ADODB.Recordset');
$rs->Open("Select * from $SQLTABLE", $conn);
if ($rs->RecordCount > 0) {...}
It's a little easier to read and thus a little bit more likely to get a good response to your question. Also, <code> tags allow others to easily download your code. You be amazed at how many fellow members of the Monastery will actually try out your code in order to better help you.
You might also want to check out Writeup Formatting Tips.
Cheers!
Brent | [reply] [Watch: Dir/Any] [d/l] |
Not all cursor types can return a RecordCount, including the default ForwardOnly cursor type. Since you aren't explicitly specifying a cursor type, you're getting the default, in which case RecordCount will return -1.
If you truly need the RecordCount, use either a Static or Keyset cursor. However, a Static cursor will load the entire recordset into memory, so you might want to avoid that. A Keyset on the other hand, only loads in the primary keys, and then uses that to cache subsets of the recordset. Of course, if someone adds a row in the meanwhile, it won't be available. Plus, there's extra overhead involved in the multiple roundtrips to update the cache as you navigate the recordset
My guess is that what you really want to know is whether or not the recordset is empty. Try:
unless ( $rs->{EOF} && $rs->{BOF} ) { ... }
That will tell you whether or not it's empty, but can still take advantage of the efficiency of a ForwardOnly cursor.
-jehuni
| [reply] [Watch: Dir/Any] [d/l] |