This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 写了段程序vbscrip t想得到RECORDSET里面记录的个数,但是却一直给我显示-1,有谁知道为什么吗?里面肯定是有几条记录的。set RS2= Server.CreateObject("ADODB.Recordset")
RS2.ActiveConnection=con
RS2.CursorType=adOpenStatic
RS2.Open sqlstring2
response.write RS2.RecordCount
-haihai(海海);
2002-10-25
{161}
(#817179@0)
-
For rational database, you can not get record count like what you do. One method is to send a SQL statement like this:"Select count(*) from YOUR_TABLE". Then you can fetch the counter from the return value.
-wins(wins);
2002-10-25
(#817192@0)
-
if not only want to know the count also the fields, I guess use .movenext to browse it better.
-ningxin0809(雁影行洲);
2002-10-25
(#817196@0)
-
But your way is relatively slow when counting for a large table.
-wins(wins);
2002-10-25
(#817200@0)
-
it is the tricky of ADO. you cannot use recordset.count to count, you have to use do while not eof() browing it and count iy yourself.
-ningxin0809(雁影行洲);
2002-10-25
(#817193@0)
-
JJ说错啦.....可以,但解释稍微复杂点,就不多说啦.. :-)
-decentboy(黄金重装甲骑士);
2002-10-25
(#817198@0)
-
really, how?
-ningxin0809(雁影行洲);
2002-10-25
(#817205@0)
-
我想如果使用disconnected recordset, 不论是什么DB都应该可以使用 recordcount....当然, 有时候disconnected recordset并不是一个好的选择... :)
-decentboy(黄金重装甲骑士);
2002-10-25
(#817233@0)
-
what kind of datasource are you connecting to?If it's Sybase,you can't use recordcount.
-goodbaby(小宝);
2002-10-25
(#817210@0)
-
SQL and Oracle neither. but 黄金重装甲骑士 said yes. I am curious.
-ningxin0809(雁影行洲);
2002-10-25
(#817221@0)
-
Maybe he is using foxbase.
-wins(wins);
2002-10-25
(#817231@0)
-
foxbase 应该也可以吧, 给你一个90%确定的回答... :-P
-decentboy(黄金重装甲骑士);
2002-10-25
(#817242@0)
-
sql server is ok.
-goodbaby(小宝);
2002-10-25
(#817249@0)
-
copied from msdnThe cursor type of the Recordset object affects whether the number of records can be determined. The RecordCount property will return -1 for a forward-only cursor; the actual count for a static or keyset cursor; and either -1 or the actual count for a dynamic cursor, depending on the data source.
-goodbaby(小宝);
2002-10-25
{297}
(#817220@0)
-
so , I guess, if we set up cusror type in Store proc as some types else, we could get the count directly. but I tried, failed ot unreliable. 黄金重装甲骑士, please let me know how you do it.
-ningxin0809(雁影行洲);
2002-10-25
(#817228@0)
-
JJ, 见 #817233. 我没有试过所有的DB, 但从理论上, 都是可以的.. :-)
-decentboy(黄金重装甲骑士);
2002-10-25
(#817266@0)
-
I never used disconnected recordset. :(
-ningxin0809(雁影行洲);
2002-10-25
(#817310@0)
-
RS2.CursorLocation=3
-mafan(麻烦);
2002-10-25
(#817254@0)
-
sounds reasonable. try later. thanks
-ningxin0809(雁影行洲);
2002-10-25
(#817306@0)
-
this is complete versionset RS2= Server.CreateObject("ADODB.Recordset")
RS2.ActiveConnection=con
RS2.CursorType=adOpenStatic
RS2.CursorLocation=3
RS2.Open sqlstring2
response.write RS2.RecordCount
-mafan(麻烦);
2002-10-25
{183}
(#817263@0)
-
谢谢诸位,没想到这么快就有了这么些的讨论,加入rs2.cursorlocation=3后,得到了正确的答案,我用的是SQL Server.但还有一个不明白,从MSDN上抄来的cursorlocation=aduserclient(好象是这个),说不认识,why?
-haihai(海海);
2002-10-25
(#817364@0)
-
the constant value for "aduserclient" is 3
-mafan(麻烦);
2002-10-25
(#817373@0)
-
cursorlocation=3 就是 ClientCursor. 当CursurType=Static & CursorLocation=ClientUser 时, 你就创建了一个 Client 端 RecordSet, 可以用做disconnected recordset
-decentboy(黄金重装甲骑士);
2002-10-25
(#817381@0)
-
但是直接写3就好的,写=aduseclient就不对, Error Type:
ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
-haihai(海海);
2002-10-25
(#817395@0)
-
aduseclient是一个const, 在VB Script中,需要加一个文件声明这个const
-decentboy(黄金重装甲骑士);
2002-10-25
(#817403@0)
-
ok,明白了,看来你对车和ASP都很厉害,谢谢大家
-haihai(海海);
2002-10-25
(#817409@0)
-
可以问问你去哪里做车的保养吗?engin oil, transmission fluid,coolant
-haihai(海海);
2002-10-25
(#817415@0)
-
sorry, should be "CursorLocation = adUseClient"
-haihai(海海);
2002-10-25
(#817387@0)
-
You have to import a file, normally under global.asa, in order to use constants.<!-- METADATA TYPE="typelib"
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
But please note that client cursor is extremely inefficient and try to avoid it as much as possible.
-jeffrey815(Smartiecat);
2002-10-25
{209}
(#817567@0)
-
cursorlocation=3. what does 3 stand for?
-haihai(海海);
2002-10-25
(#817368@0)