ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[±Ð¾Ç] (ASP±Ð¾Ç²Ä14½g) ¸ê®Æ®wÅX°Êµ{¦¡ ¤U½g

[±Ð¾Ç] (ASP±Ð¾Ç²Ä14½g) ¸ê®Æ®wÅX°Êµ{¦¡ ¤U½g

ADOª«¥ó¸s¤§Recordsetª«¥ó
«Ø¥ßRecordsetª«¥ó
    Recordsetª«¥ó¬O­t³dÂsÄý»P¾Þ§@±q¸ê®Æ®w¨ú¥X¨Óªº¸ê®Æ¡A¨ä¼Ð·Ç®æ¦¡¦p¤U©Ò¥Ü¡G
1.png
2010-5-13 01:02


¤W¦¡¤¤ªº¡yrs¡z(ª«¥ó¦W)¦P¼Ë¬O§Ú­Ì¦Û­qªº¡A¨S¦³±j¨î©Êªº©R¦W³W©w¡A¤£¹L¡A³Ì¦n¬O¨ú¤@­Ó¦³·N¸qªº¦W¦r¡A¥H¤è«K§Ú­Ì¨Ï¥Î»P°O¾Ð¡C
±µµÛ¨Ï¥Îopen¤èªk¨Ó¶}±Ò¸ê®Æªí©Î°õ¦æSelect«ü¥O¡C
°Ñ¼Æ³]©w¦p¤U¡G

  • °Ñ¼Æ¤@(Source)¡G¦¹°Ñ¼Æ¥i¬°¤@­ÓCommandª«¥ó¦WºÙ¡B¤@¬qSQL«ü¥O¡B¤@­Ó«ü©wªº¸ê®Æªí®æ¦WºÙ©Î¬O¤@­ÓStored Procedure¡F­Y«ü©w¬°¸ê®Æªí¦WºÙ«h¶}±Ò¾ã­Ó¸ê®Æªí¡A­Y¨Ï¥ÎSelect«ü¥O«h«Ø¥ßªºRecordsetª«¥ó¤º©Ò¦s©ñªº¸ê®Æ¬°¿ï¨ú¸ê®Æ¿ýªºµ²ªG¡C
  • °Ñ¼Æ¤G(ActionConnection)¡Grecordset¥i³z¹L¦¹Äݩʳsµ²connectionª«¥ó¡A¦¹°Ñ¼Æ¥i¬°Connectionª«¥ó¦WºÙ©Î¬O¤@¦ê¥]§t¡y¸ê®Æ®w³sµ²¸ê°T(ConnectionString)¡zªº¦r¦ê°Ñ¼Æ¡C
  • °Ñ¼Æ¤T(CursorType)¡Gªí¥H¦óºØ´å¼Ð¶}±Ò¸ê®Æ¡A¥]§tadOpenForwardOnly¡BadOpenKeyset¡BadOpenDynamic¡BadOpenStatic¥|ºØ¤è¦¡¡C
  • °Ñ¼Æ¥|(LockType)¡Gªí±Ä¥Î¦óºØLock«¬ºA¡A¥]§tadLockReadOnly¡BadLockPessimistic¡BadLockOptimistic¡BadLockBatchOptimistic¥|ºØ«¬ºA¡C
  • °Ñ¼Æ¤­(Options)¡Gªí¹ï¸ê®Æ®w½Ð¨Dªº«¬ºA¡A¥]§tadCmdUnknow¡BadCmdText¡BadCmdTable¡BadCmdStoredProc¥|ºØ°Ñ¼Æ¡C



Ū¨úRecordsetª«¥ó¸ê®Æ
­nŪ¨úRecordsetª«¥ó¤ºªº¸ê®Æ¡A´N¥²¶·¥ý¤F¸Ñ¸ê®Æªíªºµ²ºc¡I

Fieldª«¥ó¡G¸ê®Æ®w¤¤³Ì¤pªº¸ê®Æ³æ¦ì¬°¡yÄæ¦ì¡z¡A¦bADOª«¥ó¸s¤¤¬Û¹ïÀ³ªº´N¬OFieldª«¥ó¡AFiledª«¥ó¾Ö¦³¤T­ÓÄÝ©Ê¡A¤À§O¬°¡yName¡z(Äæ¦ì¼ÐÃD)¡B¡yValue¡z(Äæ¦ì¸ê®Æ¤º®e)¡B¡yType¡z(Äæ¦ì¸ê®Æ«¬ºA¡A¨Ò¦p¡G¼Æ¦r¡B¤å¦r¡B¤é´Á....µ¥µ¥)µ¥¤TºØ¡G
2.png
2010-5-13 01:02


Fields ¶°¦Xª«¥ó¡GFieldª«¥ó¶°¦X´N¬OFields¶°¦Xª«¥ó¡A¹ï¤ñ©ó¸ê®Æ®wªº²Õ´µ²ºc¨Ó¬Ý¡AÄæ¦ìªº¶°¦X´Nºc¦¨¡y¸ê®Æ¿ý¡z¡G
3.png
2010-5-13 01:02


¤F¸Ñ¤FRecordsetª«¥ó¤ºªº°ò¥»µ²ºc¡A§Ú­Ì¥i¥H²M·¡ªºª¾¹DFields¶°¦Xª«¥ó°ò¥»¤W´N¬O¤@­Ó¡y°}¦C¡z¡A¦]¦¹§Ú­Ì´N¥i¥H§Q¥Î°}¦Cªº¯S©Ê¡A¤]´N¬O¥i¥H§Q¥Î¡yCount¡zÄÝ©Ê°t¦X¡yFor¡z°j°é±Ô­z¨Ó¦CÁ|¥XFieldª«¥ó¡I
4.png
2010-5-13 01:02



¥t¥~§Ú­ÌÁÙ¥i¥H·f°t¤U¤èÄÝ©ÊMoveFirst¤ÎBOF±N©Ò¦³¸ê®ÆŪ¨ú
§ïÅܥثe¸ê®Æªíªº¤èªk

  • MoveNext¡G²¾¦Ü¤U¤@µ§¸ê®Æ¨Ï¨ä¦¨¬°²{¥Î¸ê®Æ¿ý
  • MovePrevious¡G²¾¦Ü«e¤@µ§¸ê®Æ¨Ï¨ä¦¨¬°²{¥Î¸ê®Æ¿ý
  • MoveFirst¡G²¾¦Ü²Ä¤@µ§¸ê®Æ¨Ï¨ä¦¨¬°²{¥Î¸ê®Æ¿ý
  • MoveLast¡G²¾¦Ü³Ì«á¤@µ§¸ê®Æ¨Ï¨ä¦¨¬°²{¥Î¸ê®Æ¿ý
  • BOF¡G¸ê®Æ¿ý«ü¼Ð¬O§_²¾¦Ü²Ä¤@µ§¸ê®Æ¿ý¤§«e
  • EOF¡G¸ê®Æ¿ý«ü¼Ð¬O§_²¾¦Ü³Ì«á¤@µ§¸ê®Æ¿ý¤§«á
  • AbsolutePosition¡G³]©w©Î¶Ç¦^²{¥Î¸ê®Æ¿ýªºµ´¹ï¦ì¸m


¸ê®Æªíªº·s¼W¡B§R°£»P­×§ï

  • Addnew¡G·s¼W¸ê®Æ¿ý
  • Update¡G§ó·s¸ê®Æ¿ý
  • CancelUpdate¡G¨ú®ø§ó·s¸ê®Æ
  • Delete¡G§R°£¸ê®Æ¿ý



¤U¨Ò§Y¬O·s¼W¸ê®Æ¿ýªº¨Ï¥Î¤èªk¡A½Ðª`·N¡G¡yrs¡z¬O¤@­Ó§Ú­Ì¦Û¦æ«Ø¥ßªºRecordsetª«¥ó¡G
  1. rs.addnew
  2. rs("«È¤á½s¸¹")="A100"
  3. rs("«È¤á¦WºÙ")="³Â»¶¾Ç¶é"
  4. rs("¦í§}")="¥xÆW¬Ù¥x¥_¿¤"
  5. rs.update
½Æ»s¥N½X
ª`·N
·í§Ú­Ì¨Ï¥Î¡yAddnew¡z¤èªk¥[¤J·s¸ê®Æ«á¡A³Ì«á¤@©wÁÙ­n¥[¤W©I¥s¡yUpdate¡z¤èªk¨Ó±N¸ê®Æ¿ý§ó·s¡A¦p¦¹¤@¨Ó·s¼Wªº¸ê®Æ¤~·|³Q¦s¶i¸ê®Æ®wÀɮפ¤¡I
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

ADOª«¥ó¸s¤§Commandª«¥ó
Commandª«¥ó
    Command ª«¥ó­t³d¹ï¸ê®Æ®w´£¨Ñ½Ð¨D¡A¤]´N¬O¶Ç»¼«ü©wªºSQL«ü¥O¡A§Y°õ¦æAction Query«ü¥O¡A«Ø¥ß¤è¦¡¦p¤U¡G
1.png
2010-5-13 01:15


¦ó¿×Action Query«ü¥O?
Action Query«ü¥O¬O«ü¯à°÷¼g¤J¸ê®Æªº«ü¥O¡A¥i¤À¬°¥H¤U´XºØ¡G

Delete «ü¥O¡G§R°£¸ê®Æ¿ý¡A»yªk¦p¤U¡G
  1. Delete From ¸ê®Æªí Where ±ø¥ó¦¡
½Æ»s¥N½X
¨Ò¦p¡G§Ú­Ì­n±N¡y­û¤u¡z¸ê®Æªí¤¤¡y¦~ÄÖ¡z¤w¸g¶W¹L¡y60¡z·³ªº¤H­û¸ê®Æ§R°£
  1. Delete From ­û¤u Where ¦~ÄÖ > 60
½Æ»s¥N½X
ª`·N¡G¦pªG«ü¥O¤¤ªº ¡yWhere ±ø¥ó¦¡¡z©¿²¤±¼¦Ó¨S¨Ï¥Î¡A«h©Ò¦³ªº¸ê®Æ¥i¬O³£·|³Q§R°£ªº³á¡I¤]´N¬O»¡¸ê®Æªíªº¤º®e±N·|¬OªÅªº¡C

Update «ü¥O¡G§ó·s¸ê®Æ¿ý¡A»yªk¦p¤U¡G
  1. Update ¸ê®Æªí set ¹Bºâ¦¡
½Æ»s¥N½X
³q±`§Ú­Ì³£·|§Q¥ÎUpdata«ü¥O¨Ó¶i¦æ¼Æ¾Çªº¹Bºâ¡A¨Ò¦p¡G¤½¥q­n¶i¦æ¦~«×Á~¸ê½Õ¾ã¡A¦]¦¹§Ú­Ì­n±N¡y­û¤uÁ~¸ê¡z¸ê®Æªí¤¤¡yÁ~¸ê¡zÄæ¦ì­È´£°ª¤­­Ó¦Ê¤À¤ñ¡G
  1. Update ­û¤uÁ~¸ê set Á~¸ê = Á~¸ê*1.05
½Æ»s¥N½X
Insert Into «ü¥O¡G·s¼W¸ê®Æ¿ý¡A»yªk¦p¤U¡G
  1. Insert Into ¸ê®Æªí(Äæ¦ì¦ê¦C) Values(Äæ¦ì¦ê¦C)
½Æ»s¥N½X
¨Ò¦p¡G¤½¥q¥[¤J¤F·sªº¦¨­û¡A§Ú­Ì­n¦b¡y­û¤u¡z¸ê®Æªí¤¤¥[¤J³o¦ì·s­û¤uªº¸ê®Æ
  1. Insert Into ­û¤u(©m¦W,¦~ÄÖ) Values(·¨¤p»x,28)
½Æ»s¥N½X
ª`·N¡GÄæ¦ì¦WºÙ»PÄæ¦ì­È¥²¶·¬Û¹ïÀ³¡I
  1. Insert Into ¸ê®Æªí(Äæ¦ì¤@,Äæ¦ì¤G,...) select ...
½Æ»s¥N½X
¦¹®æ¦¡¤D¬O±NSelect«ü¥O©Ò¿ï¨úªº¸ê®Æ¿ý·s¼W¦Ü¥t¤@­Ó¸ê®Æªí¤¤¡C
ª`·N¡G¦¹®æ¦¡¤¤ªº¨â­Ó¸ê®Æªí¥²¶·¬O¹w¥ý´N¤w¸g«Ø¥ß§¹¦¨ªºËç¡I

Select Into «ü¥O¡G«Ø¥ß·s¸ê®Æ¿ý¡A»yªk¦p¤U¡G
  1. Select * Into ·s¸ê®Æªí From ¸ê®Æªí Where ±ø¥ó¦¡
½Æ»s¥N½X
¦¹®æ¦¡¤D¬O±N©Ò¿ï¨úªº¸ê®Æ¿ý·s¼W¦Ü¥t¤@­Ó¡y·sªº¡z¸ê®Æªí¤¤¡C
¨Ò¦p¡G§Ú­Ì­n±N¡y­û¤uÁ~¸ê¡z¸ê®Æªí¤¤¡yÁ~¸ê¡zÄæ¦ì­È°ª©ó¢´¸U¤¸ªº­û¤u¤H­û¸ê®Æ«Ø¥ß¦¨¥t¥~¤@­Ó·sªº¡y°ªÁ~¤H­û¡z¸ê®Æªí
  1. Select * Into °ªÁ~¤H­û From ­û¤uÁ~¸ê Where Á~¸ê>50000
½Æ»s¥N½X
¦p¦ó°õ¦æAction Query«ü¥O
¦b­n°õ¦æ Action Query «ü¥O«D±`²³æ¡A§Ú­Ì¥u­n±NAction Query «ü¥O«ü©wµ¹¡yCommand¡zª«¥óªº¡yCommandText¡zÄÝ©Ê¡AµM«á¦A©I¥s¡yCommand¡zª«¥óªº¡yExecute¡z¤èªk°õ¦æAction Query«ü¥O¡A¦p¤U¹Ï©Ò¥Ü¡G
2.png
2010-5-13 01:15

ª`·N¡G

  • ¡ycmd¡z¬O¤@­Ó§Ú­Ì¤w¸g«Ø¥ß¦nªº¡yCommand¡zª«¥ó¡A¦Ó¡ySQL¡z«h¬O§Ú­Ì­n°õ¦æªºAction Query«ü¥O¡C
  • Action Query«ü¥Oªº¨Ï¥Î®É¾÷:°w¹ï¤j¶q¸ê®Æªº§R°£¡B·s¼W»P§ó·s¡A¨ä®Ä²v¸û°ª¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : ¡i¥Í©R¦b©I§l¶¡¡j¦òªû»¡¡G¡u¥Í©R¦b©I§l¶¡¡C¡v¤HµLªkºÞ¦í¦Û¤vªº¥Í©R¡A§óµLªk¾×¦í¦º´Á¡AÅý¦Û¤v¥Ã¦í¤H¶¡¡C¬JµM¥Í©R¥h¨Ó³o»òµL±`¡A§Ú­Ì§óÀ³¸Ó¦n¦n¦a·R±¤¥¦¡B§Q¥Î¥¦¡B¥R¹ê¥¦¡AÅý³oµL±`¡BÄ_¶Qªº¥Í©R¡A´²µo¥¦¯uµ½¬üªº¥ú½÷¡A¬M·Ó¥X¥Í©R¯u¥¿ªº»ù­È¡C
ªð¦^¦Cªí ¤W¤@¥DÃD