ADO Recordset¶ÔÏóµÄRecordCountÊôÐÔ×ÜÊÇ-1£¿ ÊÕ²Ø
×î½üÔÚÓÃasp×öÍøÒ³ºǫ́ʱ,Óöµ½ÁËÒ»¸ö·³È˵ÄÎÊÌâ,RecordSet¶ÔÏóµÄRecordCountºÍPageCount¾ùΪ-1.²»ÄÜÖ±½Ó»ñÈ¡RecordCountÊôÐÔ,ÎÒ¾ÍÏëÁËÆäËûµÄ±¿°ì·¨´úÌæ,±ÈÈç,ÀûÓÃÁËSQLµÄ¼¯º¯Êýselect Count(*) as count from table,ÕâÑùcountÖоʹ洢ÁËRecordSetµÄÊôÐÔÖµ;»òÕß,ÀûÓÃÒ»¸ö±äÁ¿´æ´¢,ÔÚÓαê´ÓÍ·µ½Î²µÄËÑË÷¹ý³ÌÖУ¬Õâ¸ö±äÁ¿Öð´Î¼ÓÒ»,×îÖվ͵õ½Á˸ÃÊôÐÔ: <% dim i i=0
set rs=conn.Open \do while not rs.EOF i=i+1 rs.MoveNext Loop %>
¿ÉÊÇ,½ÓÏÂÀ´ÒªÓõ½PageCountÊôÐÔÀ´ÊµÏÖ·ÖÒ³(AbsolutePage:Ö¸¶¨µ±Ç°Ò³;PageCount:·µ»Ø¼Ç¼¼¯ÖеÄÂß¼Ò³Êý;PageSize:Ö¸¶¨Ò»¸öÂß¼Ò³ÖеļǼ¸öÊý,ȱʡֵÊÇ10.)ÕâÖÖ·½·¨Ðв»Í¨ÁË,û°ì·¨,¾Í¿ªÊ¼µ½´¦ËѼ¯ÐÅÏ¢:
Ê×ÏÈÈÃÎÒÃÇÀ´¿´¿´ÔõôÑù»ñµÃ¼Ç¼¼¯RecordSet,ÓÐÒÔϼ¸ÖÖ: <%
set conn = Server.CreateObject(\set rs = conn.Open(sqlstring) %>
ÁíÍâÒ»ÖÖ·½Ê½£º
<% set conn = Server.CreateObject(\set cmd = Server.CreateObject(\cmd.ActiveConnect = conn
cmd.StringText = \set rs = cmd.Open conn %> ¶øÁíÍâÒ»ÖÖ°ì·¨¾ÍÊÇ:
<%
set rs = Server.CreateObject(\rs.open sql,conn,´ò¿ª·½Ê½,ËøÀàÐÍ %> ²ÎÊýÒ»±íʾÓαêÀàÐÍ£¬ÈçÏÂÉèÖ㺠²ÎÊý1 Òâ Òå 0 Ö»¶Á£¬ Êý¾ÝÖ»ÄÜÏòÏÂÒƶ¯
1 ¿É¶Áд£¬Êý¾Ý¿ÉÒÔ×ÔÓÉÒƶ¯£¬¶àÓû§Ï±ðÈ˲»ÄÜ¿´µ½ÐÂÔöÊý¾Ý£¨³ý·ÇÖØÆô¶¯£© 2 ¿É¶Áд£¬Êý¾Ý¿ÉÒÔ×ÔÓÉÒƶ¯£¬¶àÓû§Ï±ðÈË¿ÉÒÔ¿´µ½ÐÂÔöÊý¾Ý 3 Ö»¶Á £¬ Êý¾Ý¿ÉÒÔ×ÔÓÉÒƶ¯
²ÎÊý2±íʾËø¶¨ÀàÐÍ£¬ÈçÏ£º ²ÎÊý2 Òâ Òå 1 ĬÈÏÖµ£¬ Ö»¶Á 2 ±¯¹ÛËø¶¨ 3 ÀÖ¹ÛËø¶¨ 4 Åú´ÎÀÖ¹ÛËø¶¨
Ò²¾ÍÊÇ˵µÚÒ»¸ö²ÎÊýΪ1»ò2µÄʱºò£¬²ÅÄÜÓÐrecordcount
ËùÒÔÒ²¿ÉÒÔÓÃrecordset.open´ò¿ªÊý¾ÝÔ´: rs.CursorLocation = adUseClient rs.CursorType = adOpenStatic rs.open sqlstring,conn
ÔÚÎҵijÌÐòÖÐ,¸ÄΪµÚ¶þÖÖ´ò¿ª·½Ê½¾Í¿ÉÒÔÕýÈ··ÃÎÊRecordSetµÄÄÇЩÊôÐÔÁË.¾ßÌå¾ÍÊÇ: rs.Open sqlstring,conn,1,3
ÄÇôCursorLocationºÍCursorTypeµ½µ×ÊÇʲô¶«Î÷,ÄܲúÉúÕâô´óµÄÓ°Ïì? (1)CursorLocation:
ÉèÖûò·µ»ØÓαêÒýÇæµÄλÖÃ, ¿ÉÉèÖÃΪÒÔÏÂij¸ö³£Á¿µÄ³¤ÕûÐÍÖµ:
adUseNone: ûÓÐʹÓÃÓαê·þÎñ.(¸Ã³£Á¿Òѹýʱ²¢ÇÒֻΪÁËÏòºó¼æÈݲųöÏÖ) adUseClient:
ʹÓÃÓɱ¾µØÓαê¿âÌṩµÄ¿Í»§¶ËÓαꡣ±¾µØÓαêÒýÇæͨ³£ÔÊÐíʹÓõÄÐí¶à¹¦ÄÜ¿ÉÄÜÊÇÇý¶¯³ÌÐòÌá
¹©µÄÓαêÎÞ·¨Ê¹Óõģ¬Òò´ËʹÓøÃÉèÖöÔÓÚÄÇЩ½«ÒªÆôÓõŦÄÜÊÇÓкô¦µÄ¡£adUseClientBatch Óë adUseClient ͬÒ壬Ҳ֧³ÖÏòºó¼æÈÝÐÔ¡£
µ½ÕâÀï´ó¼ÒÓ¦¸ÃÃ÷°×ΪʲôÎÒÃǵÄÓαê»á³öÎÊÌâ¼°½â¾ö°ì·¨ÁË. adUseServer:
ĬÈÏÖµ¡£Ê¹ÓÃÊý¾ÝÌṩÕß»òÇý¶¯³ÌÐòÌṩµÄÓαꡣÕâЩÓαêÓÐʱ·Ç³£Áé»î£¬¶ÔÓÚÆäËûÓû§¶ÔÊý¾ÝÔ´Ëù×÷µÄ¸ü¸Ä¾ßÓжîÍâµÄÃô¸ÐÐÔ¡£µ«ÊÇ£¬Microsoft Client Cursor Provider£¨ÈçÒѶϿª¹ØÁªµÄ¼Ç¼¼¯£©µÄijЩ¹¦ÄÜÎÞ·¨ÓÉ·þÎñÆ÷¶ËÓαêÄ£Ä⣬ͨ¹ý¸ÃÉèÖý«ÎÞ·¨Ê¹ÓÃÕâЩ¹¦ÄÜ¡£
×¢:µ±ÓÃÓÚ¿Í»§¶Ë(ADOR)RecordSet»òConnection¶ÔÏóʱ,Ö»Äܽ«CursorLocationÊôÐÔÉèÖÃΪadUseClient. (2)CursorType:
ָʾÔÚRecordSet¶ÔÏóÖÐʹÓõÄÓαêÀàÐÍ,ÉèÖûò·µ»ØÒÔÏÂij¸öCursorTypeEnumÖµ£º adOpenForwardOnly(=0):
½öÏòÇ°Óαê,ĬÈÏÖµ.Ó뾲̬ÓαêÏàͬ,µ«Ö»ÄÜÔڼǼÖÐÏòÇ°¹ö¶¯.µ±ÐèÒªÔڼǼ¼¯Öе¥ÏòÒƶ¯Ê±,¿ÉÓÃÓÚÌá¸ßÐÔÄÜ. adOpenKeyset(=1):
¼ü¼¯Óαꡣ¾¡¹Ü´ÓÄúµÄ¼Ç¼¼¯²»ÄÜ·ÃÎÊÆäËûÓû§É¾³ýµÄ¼Ç¼£¬µ«³ýÎÞ·¨²é¿´ÆäËûÓû§Ìí¼ÓµÄ¼Ç¼Í⣬¼ü¼¯ÓαêÓ붯̬ÓαêÏàËÆ¡£ÈÔÈ»¿ÉÒÔ¿´¼ûÆäËûÓû§¸ü¸ÄµÄÊý¾Ý¡£ adOpenDynamic(=2):
¶¯Ì¬Óαꡣ¿ÉÒÔ¿´¼ûÆäËûÓû§Ëù×÷µÄÌí¼Ó¡¢¸ü¸ÄºÍɾ³ý¡£ÔÊÐíÔڼǼ¼¯ÖнøÐÐËùÓÐÀàÐ͵ÄÒƶ¯£¬µ«²»°üÀ¨ÌṩÕß²»Ö§³ÖµÄÊéÇ©²Ù×÷¡£ adOpenStatic(=3):
¾²Ì¬Óαꡣ¿ÉÒÔÓÃÀ´²éÕÒÊý¾Ý»òÉú³É±¨¸æµÄ¼Ç¼¼¯ºÏµÄ¾²Ì¬¸±±¾¡£ÁíÍ⣬¶ÔÆäËûÓû§Ëù×÷µÄÌí¼Ó¡¢¸ü¸Ä»òɾ³ý²»¿É¼û¡£
×¢:Èç¹û½« CursorLocation ÊôÐÔÉèÖÃΪ adUseClient£¬ÔòÖ»Ö§³Ö adOpenStatic µÄÉèÖá£Èç¹ûÉèÖÃÁ˲»Ö§³ÖµÄÖµ£¬²»»áµ¼Ö´íÎ󣬲¢½«Ê¹ÓÃ×î½Ó½üÖ§³ÖµÄ CursorType¡£
µ±ÓÃÓÚ¿Í»§¶Ë (ADOR) Recordset ¶ÔÏóʱ£¬Ö»Äܽ« CursorType ÊôÐÔÉèÖÃΪ adOpenStatic¡£
ÁíÍâÔÚ²é×ÊÁϵĹý³ÌÖÐ,·¢ÏÖÍøÉÏÒ²ÓкöàÈËÔÚÎÊÕâ¸öÎÊÌâ,¿´ËûÃÇÊÇÔõô½â¾öµÄ£¬Ë³±ã»ã×Üһϸ÷·½ÃæµÄ×ÊÁÏ:
´ò¿ª·½Ê½ÓÐÎÊÌâ°É£¬ºóÁ½¸ö²ÎÊýÉèΪ3£¬1ÊÔÊÔ£¬Ïë¸ü¸ÄÓÃ3£¬3£¬Èç¹û¼ÈÒª¼Ç¼ÊýÓÖÒªÔÊÐíÐ޸ľÍÊÔ1£¬3
rs.CursorLocation = adUseClient 'ÉèΪadUseClient
rs.Open \Óï¾ä\ '»òÕßÓαêÀàÐÍΪadOpenStatic ½«·µ»Ø¼Ç¼×ÜÊý
µ±CursorType=1ʱ£¬rs.RecordCountÊDz»¿ÉÓõÄ,½«ÆäÉèΪ3¼´¿É¡£
ÄãÖ»Òª½«RecordSetµÄÓαêÀàÐÍÉèÖÃΪ¿Í»§¶ËÓαêÀàÐ;ÍÐÐÁË: ÉèÖÃcursorlocation=adUseServer
Õâ¸öÎÊÌâÎÒÅöµ½¹ý£¬´ò¿ª²ÎÊýÖ»ÓÐÔÚΪadopenstasticµÄÇé¿öÏÂrecordcontÊôÐÔ²ÅÄÜÕýÈ·ÏÔʾÊý¾Ý¼¯ÖеļǼֵRecordset¶ÔÏóµÄÓαêÀàÐÍ»áÓ°ÏìÊÇ·ñÄܹ»È·¶¨¼Ç¼µÄÊýÄ¿¡£¶Ô½öÏòÇ°Óα꣬RecordCountÐÔ½«·µ»Ø-1£¬¶Ô¾²Ì¬»ò¼ü¼¯Óα귵»Øʵ¼Ê¼ÆÊý£¬¶Ô¶¯Ì¬ÓαêÈ¡¾öÓÚÊý¾ÝÔ´,·µ»Ø-1»òʵ¼Ê¼ÆÊý¡£
RS.OPEN SQL,CONN,A,B AΪÓαêÀàÐÍ£¬BΪËøÀàÐÍ
A: adOpenForwardOnly(=0) Ö»¶Á,ÇÒµ±Ç°Êý¾Ý¼Ç¼ֻÄÜÏòÏÂÒƶ¯ adOpenKeySet(=1) Ö»¶Á,µ±Ç°Êý¾Ý¼Ç¼¿É×ÔÓÉÒƶ¯ adOpenDynamic(=2) ¿É¶Áд,µ±Ç°Êý¾Ý¼Ç¼¿É×ÔÓÉÒƶ¯
adOpenStatic(=3) ¿É¶Áд,µ±Ç°Êý¾Ý¼Ç¼¿É×ÔÓÉÒƶ¯,¿É¿´µ½ÐÂÔö¼Ç¼ B: adLockReadOnly(=1) ȱʡËø¶¨ÀàÐÍ£¬¼Ç¼¼¯ÊÇÖ»¶ÁµÄ£¬²»ÄÜÐ޸ļǼ
adLockPessimistic(=2) ±¯¹ÛËø¶¨£¬µ±Ð޸ļǼʱ£¬Êý¾ÝÌṩÕß½«³¢ÊÔËø¶¨¼Ç¼ÒÔÈ·±£³É¹¦µØ±à¼¼Ç¼¡£Ö»Òª±à¼Ò»¿ªÊ¼£¬ÔòÁ¢¼´Ëøס¼Ç¼¡£
adLockOptimistic(=3) ÀÖ¹ÛËø¶¨£¬Ö±µ½ÓÃUpdate·½·¨Ìá½»¸üмǼʱ²ÅËø¶¨¼Ç¼¡£ adLockBatchOptimistic(=4) ÅúÁ¿ÀÖ¹ÛËø¶¨£¬ÔÊÐíÐ޸Ķà¸ö¼Ç¼£¬Ö»Óе÷ÓÃUpdateBatch·½·¨ºó²ÅËø¶¨¼Ç¼¡£ µ±²»ÐèÒª¸Ä¶¯ÈκμǼʱ£¬Ó¦¸ÃʹÓÃÖ»¶ÁµÄ¼Ç¼¼¯£¬ÕâÑùÌṩÕß²»ÓÃ×öÈκμì²â¡£¶ÔÓÚÒ»°ãµÄʹÓã¬ÀÖ¹ÛµÄËø¶¨¿ÉÄÜÊÇ×îºÃµÄÑ¡Ôñ£¬ÒòΪ¼Ç¼ֻ±»Ëø¶¨Ò»Ð¡¶Îʱ¼ä£¬Êý¾ÝÔÚÕâ¶Îʱ¼ä±»¸üС£Õâ¼õÉÙÁË×ÊÔ´µÄʹÓᣠÒýÓÃ: