8. ¸ê®Æ®w

¦b©Ò¦³ªº½Õ¬d¤¤¡Aµ§ªÌµoıVisual Basicµ{¦¡¶}µoªÌµ´¤j¦h¼Æ³£¬O¦b¶}µo¸ê®Æ®w©MClient/ServerºÝªºÀ³¥Îµ{¦¡¡C

¦b³o³¹¤¤¡Aµ§ªÌ±N¤¶²Ð¸ê®Æ®wµ{¦¡³]­p¤Î¦p¦ó¨Ï¥ÎADO¦^¶Ç±±¨î¶µ¡]bound controls¡^ªº³sµ²§Þ¥©¡]binding mechanism¡^©MADO¸ê®Æ±±¨î¶µ¡A¦ý¬O¦b¤U¦Cªº³o¨Ç§Þ³N·§©À¡A¥i¥HÀ³¥Î¦b¸ê®Æªº¨Ï¥ÎªÌ©Î¬O¨Ó·½¤è­±¡C

¦b®i¥ÜVisual Basic 6¤¤ªºADO¯à¬°§Ú­Ì°µ¤°»ò¤§«e¡Aµ§ªÌ¥²¶·«Ü§ÖªººK­n»¡©ú¸ê®Æ®wªº¬[ºc¤Î¸ê®Æ¦s¨úªº§Þ³N¡C

¸ê®Æ¦s¨ú¨ó©w
¡@

©Ò¦³¦bVisual Basic 6¤¤·sªº¸ê®Æ®w¬ÛÃö¨Ï¥Î³£¬O¥ÎMicrosoft ActiveX Data Objects (ADO)¡C¤@­Ó¥i¥HÅý±z¦s¨ú¥ô¦ó¸ê®Æ®w¤Î¸ê®Æ¨Ó·½ªº§Þ³N¡A¦p¦P¤@¨Ç¤H¦³¼g¹L³s±µ¸ê®Æ¨Ó·½ªºOLE DB Provider¡C

¹Ï8-1ºK­n«ü¥X¦bVisual Basic 6¤¤±z¥i¥H¥Î³\¦h¤èªk¨ú±o¸ê®Æ¨Ó·½¡C´N¹³±z©Ò¬Ý¨ìªº¡A¦b±z­n³s±µªº¸ê®Æ®w©MÀ³¥Îµ{¦¡¦U¼h¤§¶¡ªº¦U­Ó¸ê®Æ¦s¨ú¤èªk³£¤j¤£¬Û¦P¡CµM¦Ó¦b³o®Ñ¤¤¡A§Ú¶°¤¤¦bADO§Þ³N¡A¨ä¥¦ªº¥u¦³Â²³æ´y­z¤@¤U¡C¨M©w­n¤£­n²[»\¨üÅwªïªº¸ê®Æ¦s¨ú§Þ³N¦p¡GDAO¤ÎRDO¬O«Ü§xÃøªº¨M©w¡A¦ý¬O§Ú¥²¶·«O«ù³o¥»®Ñªº¦X²zªº¤j¤p¡C¦b³o¨M©w¤¤«ÜªY¼¢ªº¬O¨Æ¹ê¤WDAO©MRDO¨S¦³¦bVisual Basic 6¤¤§@¥ô¦óªº§ïµ½¡F©Ò¥H¦pªG±z¤w¸g¹ï©óVisual Basic 5ªº§Þ¥©«Ü¼ôªº¸Ü¡A³o´N¨S¤°»ò·sªº¦nÁ¿¤F¡C³o¨â­Óªº§Þ³N³Ì«á±N³QADO©Ò¨ú¥N¡C±z¥i¥Hµo²{¤@¨Ç¦n®Ñ©M¨ä¥L¸ê°T¨Ó·½¬O¦³ÃöDAO¤ÎRDOªº¡A¹³¬OWilliam R. Vaughn©Ò¼gªº¡msuperb Hitchhiker's Guide to Visual Basic and SQL Server¡]Microsoft Press, 1998¡^¡n¡AÁöµM¥»®Ñ¨S¦³½g´T²`¤Jªº¥h¼gDAO©MRDO¡A±z¦Ü¤Ö­n¥h¼sªxªº¤F¸Ñ¥¦­Ì¬O¦p¦óªº¹B§@³o¼Ë¥i¥HÀ°§U±z¤F¸ÑADO±aµ¹±zªº®Ä¯q¬O¤°»ò¡Cµ§ªÌ¥²¶·´y­z¤@¤U¤§«e¥i¥Îªº¤u¨ã¤Î¦p¦ó±NADO©Mªº§Þ³N°µÃöÁp¡C


¡@

¨Ï¥ÎODBC¡BDAO¡BRDO¤ÎADO¦s¨ú¸ê®Æ®w

ODBC
¡@

ODBC¬O¡u¶}©ñ¦¡¸ê®Æ®w³s±µ¡v¡]Open Database Connectivity¡^ªºÁY¼g¡A¥¦ªº¥\¯à¬OÅý±z¥i¥H³s±µªñºÝ©Î»·ºÝªº¸ê®Æ®w¡CMicrosoft¶}©l³o­Ó§Þ³N¥D­n¬O¬°¤F¯à³s±µ¤@¨Ç¤£¦P³W®æªº¸ê®Æ®w-dBASE¡BMicrosoft FoxPro¡BMicrosoft Access¡BMicrosoft SQL Server¡BOracleor¬Æ¦Ü©ó¬O¡u¼Ð©ú³rÂI¤À¬É¤å¦rÀÉ¡v¡]plain comma-delimited text files¡^-¥u­n¨Ï¥Î¤@¯ëªºAPI¡C¹q¸£³s±µ¨ìDDLªº°õ¦æÀ³¥Îµ{¦¡¥s°µODBCÅX°Êµ{¦¡ºÞ²z­û¡A¥¦Âà°e©R¥O¨ì¡]¤Î¨ú±o¸ê®Æ±q¡^ODBCÅX°Êµ{¦¡¯S§O«ü©wªº¸ê®Æ®w¡CViusaul Basic 2¬O²Ä¤@­Ó¦³¯à¤O³s±µ¨ìODBC¸ê®Æ¨Ó·½ªºµ{¦¡»y¨¥ª©¥»¡C±q¨º¤§«á¥i¥H¨Ï¥ÎODBCÅX°Êµ{¦¡´N¼W¥[ªº«D±`§Ö³t¡A­«ÂI¬O´X¥G¨S¦³¤@­Ó°Ó·~³nÅé¸ê®Æ®w¬O¤£´£¨ÑODBCÅX°Êµ{¦¡¡C

ODBCªº§xÃøÂI¦b©ó´£¨Ñ¤@­Ó¤@¯ëªº¤¶­±µ¹©Ò¦³¤£¦Pªº¸ê®Æ®w¡C²z½×¤W¡A±z¥i¥H±N¤@­Ó¨Ï¥ÎODBCªºÀ³¥Îµ{¦¡¸ò¤@­ÓAccess¸ê®Æ®w³s±µ¡A¥H«á¦A²³æ¦a­×§ï«áºÝªºODBCÅX°Êµ{¦¡©M­ì©lµ{¦¡¤¤ªº¤Ö³\µ{¦¡½XÂX¤j³W¼Ò¦¨¤@­ÓSQL Server¸ê®Æ®w¡C³o¬O¥i¥H°µ¨ìªº¡A¦]¬°±z°e¨ì¸ê®Æ®wªº©Ò¦³ªº©R¥O¬O¼Ð·ÇSQL»yªk¡CSQLµ²ºc¤Æ¬d¸ß»y¨¥¡]Structured Query Language¡^¬O¤@­Ó±Mªùµ¹¸ê®Æ®w¨Ï¥Îªº¥iµ{¦¡¤Æ»y¨¥¡C¡]½Ð¬Ý ¡qSQL³t¦¨¡r ¡Aµy«á¦b³o­Ó³¹¸`¤¤·|¹ïSQL§@¤@­Ó¤¶²Ð¡^¡C¹ê»Ú¤W¡AÁöµM³z¹LODBC¼h¯Å¯à°÷Âà´«³o¨Ç¼Ð·ÇªºSQL©R¥O¦¨¬°«ü©w¸ê®Æ®wªº¿W¯S»y¨¥¡A¦ý¬OODBCµ{¦¡³]­p®v«o®É±`¶¹LODBC½Ķ¤ÞÀº¡A¦Óª½±µ±N©R¥O°e¨ì¸ê®Æ®w¡]¦³¤@¨Ç¤wª¾ªºpass-through¬d¸ß©Î©R¥O¡^¤£¥Î¦h»¡¡A³o¼Ë°µ·|³y¦¨²¾´Ó³o­ÓÀ³¥Îµ{¦¡¨ì¨ä¥L¸ê®Æ®w®Éªº¤@­Óªýê¡C

¦Ü¤Ö©M³\¦h¨ä¥L¸ê®Æ®w¦s¨ú§Þ³N¨Ó¤ñ¸û¡AODBC¬O¦³®Ä²vªº¡CODBCªº¨ä¥¦Àu¶Õ¬O¥¦¦P®É¤ä´©16¦ì¤¸¤Î32¦ì¤¸ªºAPI¡A¦bVisual Basic 3©MVisual Basic 4ªºÀ³¥Îµ{¦¡¤¤¥¦¬O¤@­Ó²{¦¨¥i¥Îªº§Þ¥©¡C²Ä¤Tª©ODBC¦³¼W¥[¤@¨Ç´£ª@®Ä¯àªº§Þ¥©¡A¦p¡uconnection pooling¡v¡A·N«ä´N¬OODBCÅX°Êµ{¦¡¦b¥Î¤áºÝ¥i¥H­«ÂШϥΤw¦s¦bªº³sµ²³o¹ïµ{¦¡¨Ó»¡¬O¥i¦æªº¡C¨Ò¦p¡G±zªºµ{¦¡¥i¥H¥´¶}©M³sµ²¦h­Ó³sµ²¨ìªº¸ê®Æ®w¡A¦ý¬OODBC³q±`¨Ï¥Î¦P¤@­Ó³sµ²¡A¦]¬°¥´¶}¤@­Ó³sµ²¬O¯Ó®Éªº§@·~-¤@¦¸·|ªá¥h´X¬íÄÁ-connection pooling¨Ï±zªºµ{¦¡¯à¦³§ó¦hªº¦^À³¡CMicrosoft Transaction Server´N¨Ï¥Îconnection pooling§ïµ½ActiveX¥´¶}³sµ²ªº®Ä¯à¡C

µM¦Ó¨Ï¥ÎODBC¯S§O¬O¹ïVisual Basicµ{¦¡³]­p®v¨Ó»¡¬O¤£®e©öªº¡CAPI¨ç¼Æ¨Ï¥Î½ÆÂø¡A¦Ó¥B¦pªG¤£¤p¤ß¦³¤F¿ù»~±`±`·|¾É­P±zªºÀ³¥Îµ{¦¡²£¥Í¡u­«¤j¿ù»~¡v¡]fatal error¡^¡]¦pªGµo¥Í¦b±z¶}µo®ÉªºÀô¹Ò¡A±z¬Æ¦Ü³s¦sÀɪº¾÷·|³£¨S¦³¡^¡C°ò©ó³o­Ó²z¥Ñ¡AVisual Basicµ{¦¡³]­p®v¦b¼gµ{¦¡®É¥u¦³¤Ö¼Æ·|¦³¿³½ìª½±µ©I¥sODBC¨ç¼Æ¡A¤j¦h¼ÆªºVisual Basic²{¦¨¥i¥Îªº¸ê®Æ¦s¨ú§Þ¥©¥i¥H¨Ï¥ÎODBCÅX°Êµ{¦¡·í¤¤¤¶¼h¡A©Ò¥H¦³®É±z¥i¥H¥Îª½±µAPI©I¥sÂX¤j¨ä¥¦ªº§Þ¥©¡]³q±`¬O¬[ºc¦bRDO¤W¡^¡A¤£©¯ªº¡A±z¤£¥i¥H©MADO¤@°_¨Ï¥Î¡G§Y¨ÏÁöµMADO¤¤¨Ï¥ÎODBCÅX°Êµ{¦¡¡A±zÁÙ¬O¤£¯à±N¦P¤@­Ó¸ê®Æ®w³s±µ¦P®É¨Ï¥ÎADOµ{¦¡½X©MODBCµ{¦¡½X²V¦X¨Ï¥Î¡C

¬JµM±zªºVisual Basicµ{¦¡¤¤¤£ª½±µ¨Ï¥ÎODBC API©I¥s¡A±z´N¥²¶·¼ô±x¤F¸Ñ¤@¨Ç°ò¥»§Þ³Nªº·§©À¡C¨Ò¦p¡G©Î³\±z±N¥Î¤@­Ó¸ê®Æ¨Ó·½¦WºÙ¡]Data Source NameÁY¼g¬°DSN¡^¨Ï¥ÎADO¡CDSN¬OÀ³¥Îµ{¦¡­n¥¿½Tªº³s±µ¸ê®Æ®wªº¤@²Õ­È¥]¬A¸ê®Æ®w¥D¾÷ªº¾÷¾¹¦WºÙ¡]¦pªG±z¨Ï¥Îªº¬Oclient-server¤ÞÀº¦pSQL server©ÎOracle¡^¡B«ü©w¸ê®Æ®wªº¦WºÙ©Î¸ô®|¡B³s±µ¹O®É¡]¤]´N¬O·í¹Á¸Õ³s±µ«ü©wODBCÅX°Êµ{¦¡©ñ±ó¤Î¦^À³¤@­Ó¿ù»~µ¹©I¥sªºÀ³¥Îµ{¦¡ªº¬í¼Æ¡^¡A¤u§@¯¸¤ÎÀ³¥Îµ{¦¡ªº¦W¦rµ¥µ¥¡C

±z¥i¥H¥Î«Ü¦h¤èªk«Ø¥ßDSN¡A¤£ºÞ¦bVisual Basic 6Àô¹Ò¤º©Î¥~¡CODBC¸ê®ÆºÞ²z­û¬O±±¨î¥xªº¤@­Ó¤pÀ³¥Îµ{¦¡¥i¥HÅý§Ú­Ì«Ø¥ß¤@¨ÇDSN©M³]©w¤@¨Ç­È¡C±z¥i¥H±q¦hºØDSN¤¤¿ï¾Ü³QÀx¦s¦b¨t²Îµn¿ý­È¤¤ªº¨Ï¥ÎªÌ¸ê®Æ¨Ó·½¦WºÙ¡]User DSN¡^¡A¥u¥i³Q¯S©wªº¤H¨Ï¥Î¡A¤£¥i¥H©M¨ä¥Lªº¤H¦@¨É¡C¨t²Î¸ê®Æ¨Ó·½¦WºÙ¡]System DSN¡^¤]¬O³Q¦s¦b¨ä¥Lªº¨t²Îµn¿ý­È¤¤¦ý¬O¤£¦Pªº¬O¡A¨ä¥Lªº©Ò¦³¨Ï¥ÎªÌ³£¥i¥H¬Ýªº¨ì¡A¥]§tMicrosoft Windows NTªA°È¡C³Ì«á¡AÁÙ¦³¤@ºØÀx¦s¬°ªþ¥[ÀɦW.dsnªºÀɮ׸ê®Æ¨Ó·½¦WºÙ¡]File DSN¡^¥i¥Hµ¹©Ò¦³¨Ï¥ÎªÌ¨Ï¥Î¡]´£¨Ñµ¹¨º¨Ç¦³¦w¸Ë¥¿½TªºODBCÅX°Êµ{¦¡ªº¾÷¾¹¡^¡CFile DSN«Ü®e©öªº¥i¥H½Æ»sµ¹¨ä¥Lªº¹q¸£¡A©Ò¥H¦w¸Ë´²µo¸û®e©ö¡F¦b¥t¤@¤è­±¡AÀ³¥Îµ{¦¡»Ý­nª¾¹DDSNªº©Ò¦b¦ì¸m¡A©Ò¥Hµ{¦¡½X¥²¶·­n´£¨Ñ§¹¾ãªº¸ô®|§ä¨ì.dsnÀɮסA±z¥²¶·Àx¦s¸ô®|¦b¬Y¨Ç¦a¤è¡]¦p¡A¦bINIªºÀɮפ¤¡^¡A³o¬O¦bUser©ÎSystem¸ê®Æ¨Ó·½¦WºÙ©Ò¤£»Ý­nªº¡C

·í±z¨Ï¥ÎODBC®É¦pªG±z¤£·Q³Q­¢³]©wDSN¡A±z¥i¥H´£¨Ñ©Ò¦³³s±µ¸ê®Æ®wªº¸ê°T¡ÐÅX°Êµ{¦¡¦WºÙ¡B¸ê®Æ®w¦WºÙ¤Î¸ô®|µ¥µ¥¡Ð©ñ¦b±zªºµ{¦¡½X¤¤¡C³o´N¬O©Ò¿×ªºµL¸ê®Æ¨Ó·½¦WºÙ¡]DSN-less¡^³s±µ¡A¨º¸g±`¬O¸û¦³®Ä²vªº¡A¦]¬°¦b±zÂಾÀx¦sODBCÅX°Êµ{¦¡¨ì¨t²Îµn¿ý¤¤©ÎÀÉ®×DSN®É¡ADSN-less·|Åý¶}µoªÌªá¸û¤Öªº®É¶¡¡C

­º¥ý¦bODBC±±¨î­±ªOªº¤T­Ó­¶ÅÒ¹ï¸Ü²°¥i¥HÅý§Ú­Ì«Ø¥ß¡B§R°£¡B©M³]©w©Ò¦³ªºDSN¡C´N¹³±z¦b¹Ï8-2¤¤©Ò¨£¡A«Ø¥ß¤@­ÓDSN¸g±`»Ý­n¥´¶}¼Æ­Ó¹ï¸Ü²°¡A ÅX°Êµ{¦¡ ­¶ÅÒÅã¥Ü©Ò¦³¤w¦w¸ËªºODBCÅX°Êµ{¦¡©MÅý±z®Ö¹ïª©¥»¸¹½X¡]¦³®É·í±z·Q¦w¸Ë¨ì¨Ï¥ÎªÌ¾÷¾¹¤W¡A«o¤£¯à¥¿±`°Ê§@®É¬Û·í¦³¥Î¡^Visual Basic 6¦³ªþ¥[¤@¨ÇODBCÅX°Êµ{¦¡¡]¥i¥H¦b¹Ï8-3¤¤¬Ý¨ì¤@¨Ç¡^¡A±z¤]¥i¥H¦V¨ä¥Lªº²Ä¤T¨ó¤O¼t°Ó­qÁÊ¡C

ODBC¸ê®Æ¨Ó·½ºÞ²z­ûÀ³¥Îµ{¦¡¤¤ªº°lÂÜ­¶ÅÒ¡]Tracing tab¡^¥i¥H¬°©Ò¦³ODBC°Ê§@³]©w°O¿ý¡]log¡^Àɮ׸ô®|¡AÁYµuODBCÀ³¥Îµ{¦¡ªº°£¿ù¡]³o¿ï¶µ·í±z³z¹LDAO¡BRDO©ÎADO¶¡±µ¨Ï¥ÎODBC¤]¬O«Ü¦³¥Îªº¡^¡C³Ì·sªºODBC¸ê®Æ¨Ó·½ºÞ²z­ûÀ³¥Îµ{¦¡ª©¥»ÁÙ¯à±Ò°ÊMicrosoft Visual Studio Analyzer¥i¥HÅý±z³z¹Lºô¸ôºÊµø±zªºµ{¦¡¹B§@¡C

¦b³sµ²¦@¥Î°Ï¡]Connection Pooling¡^­¶ÅÒ¤¤¡A±z¥i¥H±Ò°Ê©Î¬O°±¤î¨C­Ó¯S©wªºODBCÅX°Êµ{¦¡¥Îªº³sµ²¦@¥Î°Ï¡C«ÜÃø±o·|»Ý­n¥hÅܰʳo¨Ç³]©w¡Aµ§ªÌ«Øij±z¤£­n¥hÅܰʳ]©w°£«D±z«Ü²M·¡ªºª¾¹D±z¦b°µ¤°»ò¡C³Ì«á¦bÃö©ó¡]About¡^­¶ÅÒ¤¤±z¥i¥Hª¾¹D©Ò¦³ªºODBC¤l¨t²ÎªºDLL¦ì¸m¤Îª©¥»¡C


¡@


¡@

DAO
¡@

DAO¡A©ÎºÙ¸ê®Æ¦s¨úª«¥ó¡]Data Access Objects¡^¦b©Ò¦³¨Ï¥ÎVisual Basic 3¶}µo¸ê®Æ®wÀ³¥Îµ{¦¡ªºµ{¦¡³]­p®v¤ß¤¤¬O¦³¦a¦ìªº¡CDAO¬O¤@­Óª«¥ó¾É¦V¤¶­±³s¨ìMicrosoft Jet¤ÞÀº¡A³o­Ó¤ÞÀº¬O«Ü±jªº¦s¨ú¤èªk¡Aµ{¦¡¶}µoªÌ¥i¥H¨Ï¥ÎAccess³]­p¤@­ÓMDB¸ê®Æ®wµM«á¨Ï¥ÎVisual Basic DAO¥h¶}±Ò¸ê®Æ®wÂ^¨ú¸ê®Æ°O¿ý©MºÞ²z¥æ©ö¡CDAO³Ì¦nªº¦a¤è¬O¥¦¨S¦³­­¨î±z¤@©w­n¨Ï¥ÎJet¤ÞÀº¸ê®Æ®w¦]¬°±z¥i¥Hª½±µ¶}±Ò¥ô¦ó¦³ODBCÅX°Êµ{¦¡ªº¸ê®Æ®w¡A©Î¬O±z¥i¥H¨Ï¥ÎJet¤ÞÀº³s±µªí®æ¡A¨º¬O¤@­ÓÄÝ©óMDB¸ê®Æ®wªºµêÀÀªí®æ¡A¨Ã¥B¥i¥H³z¹L¨ä¥LªºODBC¨Ó·½¨Ó¥¿½T¦a¦^´_©MÀx¦s¸ê®Æ¡C

Áa¨Ï¥i¥H¨Ï¥ÎDAO¥h¦s¨ú«DJet¤ÞÀºªº¸ê®Æ¨Ó·½¡A³o®É¦b±z¤ß¤¤À³¸ÓÁÙ¬O­n¦³¤@­Ó²M·¡ªºÆ[©À¡A¨Ò¦p¡AÁaµM±zªºÀ³¥Îµ{¦¡¤£¨Ï¥ÎMDB¸ê®Æ®w¡A±z¤´µM¥²¶·¸ü¤JJet¤ÞÀºDLL¡]°ÊºA³sµ²µ{¦¡®w¡^¦b°O¾ÐÅ餤¡C¡]¦b´²µo³nÅé®É¤]¥²¶·±NDDLµ¹¨ä¥L¨Ï¥ÎªÌ¡^¡C§óÁVªº¬O¡ADAO¤£Åý±zª½±µ¨Ï¥ÎODBC APIªº¨ç¦¡¡A¨Ò¦p¡G±z¤£¯à°õ¦æ«D¦P¨Bªº¬d¸ß©Î¥ÎDAO³s±µ¡A¤]¤£¥i¥H¨Ï¥Î¦h­«µ²ªG³]©w¡]multiple result sets¡^¡C

Visual Basic 3¬O²Ä¤@­Ó¥]§t³o¸ê®Æ±±¨î¶µªºª©¥»¡A¥¦¥i¥H¦b¤@­Óªí³æ¤¤¥[¤JDAO

±±¨î¶µÅý±z¦êÁp¤@­Ó©ÎªÌ§ó¦hªº±±¨î¶µ¡A³s±µ¨ì¤@­Ó¸ê®Æ¨Ó·½µM«á¦A´£¨Ñ¤@¨Ç«ö¶s±N±z³s±µªº¸ê®Æ®wªí®æªºÀ³¥Îµ{¦¡§@¦¨¨ã¦³¾ÉÄýªº¥\¯à¡C¤@¶}©l±z·|ı±o¸ê®Æ±±¨î¶µ¦ü¥G¬O­Ó¤£¿ùªº¤u¨ã¡A¦]¬°¥¦Åý±z¨³³t¦a¬°¸ê®Æ®w³Ð³y¦³®Ä²vªº¨Ï¥ÎªÌ¬É­±¡CµM¦Ó¨ì«á­±ªº¤@¨Ç´ú¸Õ«á¡A¶}µoªÌ¤j¦h©ñ±ó³o¸ê®Æ±±¨î¶µ¡F¦]¬°¥¦¦³«Ü¦h­­¨î¬O«ÜÃø§JªAªº¡A°£¤F®Ä¯à¦Ò¶q¡A¸ê®Æ±±¨î¶µ¦³¤@­ÓÄY­«ªº¤£§QÂI:¥¦³sµ²±zªº«eºÝÀ³¥Îµ{¦¡¨ì«áºÝ¸ê®Æ®w¸Ìªº¸ê®Æ¡A°²¦p±zµy«á·Q­n¦b±zªºÀ³¥Îµ{¦¡¤¤¥[¤J½ÆÂø¦³®ÄªººÞ²z¨ì¸ê®Æ®wÄæ¦ì©Î¦s¨ú¨ä¥L¸ê®Æ®wªº¸ê®Æ¡A¥²¶·­×¥¿±zªº¥þ³¡µ{¦¡¤¤ªº³æ¤@¼Ò²Õ¡A³o¨Ç¡]»P¨ä¥Lªº°ÝÃD¡^¬O¨å«¬ªº¤@­Ó2-tier¡]¼h¡^¬[ºc¡A³o­Ó¯ÊÂI¨ä¹ê¦b3-tier¡]©ÎªÌN-tier¡^¬[ºc¬y¦æ«á´N³Q©ß±ó¤F¡A¤@­Ó©Î¬O§ó¦hªº¤¤¤¶¼h¦b³oÀ³¥Îµ{¦¡©M¸ê®Æ®w¤§¶¡¥N³Ò¤F¡A½Ñ¦p¡G¸ê®Æ¦³®Ä©Ê¡B°Ó·~³W«h¡B¤u§@¶q¥­¿Å¡B©M¦w¥þ©Ê¡C­ü¡A¸U¤@±z·Q­n©ê«ù³oN-tier­õ¾Ç¡AÁÙ¬OÄU±z§Ñ°O¸ê®Æ±±¨î¶µªººØºØ§a¡I

Visual Basic 4¥]§t§ïµ½ªºDAO 3.0ª©¥»¡A¥¦³Q½á»P¤@­Ó¯S§OªºDLL¤]¤¹³\µ{¦¡³]­p®v¥H32-¦ì¤¸§Þ³N³s±µ16¦ì¤¸¸ê®Æ®w¤u§@¡CVisual Basic 5ªºµ{¦¡³]­p®v¯à¨Ï¥ÎDAO 3.5¡A¦bVisaul Basic 6ªº®M¸Ë¤¤¡A±z±Nµo²{¦³DAO 3.51¡A¤jÅé¦Ó¨¥¬O³£©M¥ý«eª©¥»Ãþ¦ü¡C·L³n¤½¥qªº«Øij¬O¤£­p¹º§ó¶i¤@¨B§ïµ½DAO¡A§Y¨ÏMicrosoft Office 2000«Å§G¤ä´©µÛDAO 4¡C

RDO
¡@

RDO¡A©ÎªÌºÙ¤§¬°»·ºÝ¸ê®Æ±±¨î¶µ¡A¬O¥Ñ·L³n¤½¥qªì¦¸²Õ¦X³æ¯ÂªºDAO©M±j¤jªºdirect¡]ª½±µ¦s¨ú¡^ ODBC API³]­p¥Xªº¡CÄ~DAO¤§«áRDO¬O¤@­Ó§t½k«¬¦¡ªºª«¥ó¼Ò«¬¡A¦ý¥¦Â¶¹LJet¸ê®Æ®w¤ÞÀº¤ÎDAO DLLª½±µªº¦bODBCÅX°Êµ{¦¡¤U¤u§@¡CÀ³¥Îµ{¦¡¦bRDO¤W¥u»Ý¸ü¤J¤@­Ó¤p¤pªºDLL´N¥i¥H¥N´À³o·¥¯Ó¸ê·½ªºJet¸ê®Æ®w¤ÞÀº¡C§ó­«­nªº¬ORDO¯S§O³Q³]­p©MODBC¸ê®Æ¨Ó·½¤@°_¤u§@¡A©Ò¥H¥¦ÅãÅS¥X¤£¯à±qDAO§@¦s¨úªº¨ç¦¡¡ARDO¬O32-¦ì¤¸§Þ³N¡A©Ò¥H¡A¦b16¦ì¤¸ªºÀ³¥Îµ{¦¡¤¤¤£¯à¨Ï¥Î¡C

Visual Basic 4¤¶²ÐRDO²Ä¤@­Óª©¥»¡A¦bVisual Basic 5¤¤¥]§t¤FRDO 2¡A¥¦§ïµ½¤F³o­Ó¤ÞÀº¡A²{¦b³Ì·sªºª©¥»¬O¤@­Ó¦¨¼ôªº²£«~¡A¦P®É¤]¤ä«ùµÛ¤@­Ó·sªºµ{¦¡¼g§@¨Ì¾Ú¨Æ¥óªº¼Ò«¬¡A¹ï¥H«D¦P¨Bªº¾Þ§@¨Ó»¡¨º¬O«D±`¦³À°§Uªº¡AÁöµMRDOªºµo®i¦ü¥G¦³°±¤î¡A¦ý¬OVisual Basic 6¤´µM¥]§tª©¥»2¨Ã¥H¤£©úÅ㪺§ïµ½¨Ó´À¥NVisual Basic 5ªºª©¥»¡C©Ò¥HRDO¬O¥t¥~ªººÉÀY¡DÁöµM·L³n¤½¥q¦ü¥G¦n¹³µªÀ³¿n·¥ªº¤ä´©RDO¡A¦ý³£¦bADO¤W¦ü¥G±o¨ì§ïµ½¡C

RDO²Ä¤@ª©©M²Ä¤Gª©©MRemoteData±±¨î¶µªþ¦b¤@°_¡A±z¥i¥H³sµ²±±¨î¶µ¨ì»·ºÝªº¸ê®Æ¨Ó·½¡A¦b³o­Ó·Pı¤¤¡ARemoteData±±¨î¶µ¤À¨É©Ò¦³¸ê®Æ±±¨î¶µªºÀu¶Õ¤Î¤£§QÂI¡A¥]§t©Mn-tier¬[ºcªº°ÝÃD¡C

ODBCDirect
¡@

Visual Basic 5ÁÙ¥]§t¥t¥~¤@ºØ¸ê®Æ¦s¨ú§Þ³N¡A¥s°µODBCDirect¡]ODBCª½±µ¦s¨ú¡^¡A¥i¥H¤¹³\µ{¦¡³]­p®v±Ä¥ÎRDO¦ý¬O¨Ï¥ÎDAOªº»yªk¡AODBCDirect³Qºc«ä¦b·í§@¤@­Ó¥æ©ö§Þ³N¥Î¨Ó¨ó§UVisual Basicµ{¦¡³]­p®vÂಾDAO/JetÀ³¥Îµ{¦¡¨ì§ó±jªºClient/Server¬[ºc¡C²z½×¤W¡A¥u­n§ó§ï¤w¦s¦bDAOµ{¦¡¤Ö¼ÆªºÄÝ©Ê¡A¨º¨ÇÀx¦s¦bJet¤ÞÀºªº¸ê®Æ®w´N¥i¥HÂà´«¦¨Client/ServerÀ³¥Îµ{¦¡³sµ²¨ì©Ò¦³ODBC¸ê®Æ¨Ó·½¡CODBCDirect¤£À³³Qµø¬°¥¦¦Û¤vªº¤@­Ó§Þ³N¡A¥¦§ó¹³¬O¥i¥H¥Î¨ÓÂà´«À³¥Îµ{¦¡¸`¬Ù®É¶¡ªº¤@­Ó¥©­p¡A¨Ò¦pRDO 2¦³³\¦h·sªº¯S¦â¡Ð·sªº¨Æ¥óµ{¦¡¼Ò²Õ¡A¤£¯àÅýODBCDirect·í§@ÀuÂI¬O¦]¬°¥¦¥²¶·»PDAOµ{¦¡½X¬Û®e¡C¦¹¥~¡AODBCDirect°ò©óRDO©Ò¥H¥u¯à¨Ï¥Î¦b32¦ì¤¸ªºÀ³¥Îµ{¦¡¤¤¡C°ò©ó³o¨Ç²z¥Ñ¡A°£«D±z¦³¤@­Ó«D±`¤j¥B½ÆÂøªºDAO/Jet Visual BasicÀ³¥Îµ{¦¡»Ý­nºÉ§Öªº²¾´Ó¨ì¨ä¥L¸ê®Æ®w¤W§_«h¤£­n®ö¶O±zªº®É¶¡¦bODBCDirect¤W¡C

OLE DB
¡@

OLE DB¬O¤@­Ó§C¶¥ªº¸ê®Æ¦s¨ú§Þ³N¡A´N·L³n¤½¥qªº·N¹Ï¨ÓÁ¿¡A¬O­n¥H³o­Ó§Þ³N¨Ó¨ú¥NODBC¡A·í§@¥D­n³s±µ¨ì¸ê®Æ®wªº§Þ³N¡COLE DB¬Û¹ï¨ìODBCÅX°Êµ{¦¡¨Ó»¡´N¬OOLE DB Providers¡]´£¨ÑªÌ¡^¡A´N¦³¦p¤@®y¾ô³s±µÀ³¥Îµ{¦¡©M¸ê®Æ®w¤§¶¡ªº§@¥Î¡AÁöµMOLE DB¬O¤@­Óªñ¨Óªº§Þ³N¡A¦ý¬O±z«o¯àµo²{OLE DB Providers´£¨Ñªº¤j¦h¬°¬y¦æªº¸ê®Æ®w¡F¦Ó¥B¨ä¥LªºOLE DB Providers±N¦b¤£¤[«á¥¿¦¡ÄÀ¥X¡C¤£½×ODBC»POLE DB§Þ³N¬O§_§¹¥þ¦a¤£¦P¡A¥¦­Ì«o©úÅ㪺Ãþ¦ü¡C²Ä¤@¡AOLE DB¬O¬[ºc¦bCOM¤§¤W¡A³o­Ó¬[ºc¤w¸gÃҹꧧ¤j¨ì¨¬°÷¨Ó·h²¾¤j¶qªº¸ê®Æ³q¹Lºô¸ô¡C

²Ä¤G¡AOLE DB±N¥¦¦Û¤v­Éµ¹¥ô¦óÃþ«¬¸ê®Æ¨Ó·½ªº³s±µ¤u§@¡A¤£¦A¥u¬O©MODBCÅX°Êµ{¦¡¡ÐISAM(¥[¦³«ü¼Ðªº´`§Ç¦s¨ú¼Ò¦¡)¸ê®Æ®w¦³Ãö«Y¡C

OLE DB¬O·L³n¤½¥qªº´¶¹M¸ê®Æ¦s¨ú(UDA)µ¦²¤ªº¤@³¡¥÷¡A¯à°÷¨Ï±zŪ¨ú©M³B²z¸ê®Æ¤£ºÞ¥¦¬O¦b­þ¸Ì¡A¤£»Ý­n¥ýÂà´«¥¦©MÂà¤J¥¦¨ì¤@­Ó§ó¥[¶Ç²Îªº¸ê®Æ®w¡C¨Ï¥ÎOLE DB Providers¡A±z¯à³B²z¹q¤l¶l¥ó°T®§¤¤ªº¸ê®Æ¡AHTMLºô­¶¡A¸Õºâªí»P¤å¦r¤Î¤å¥ó¡A¬Æ¦Ü©ó§ó¦h¨ä¥L¥~¨Óªº¸ê®Æ¨Ó·½¡CVisual Basic 6¥¦¦Û¤v¦ñÀHµÛMicrosoft Jet¸ê®Æ®w¤ÞÀº¡BSQL Server¡BFoxPro¡BtextÀɮסB©MOracle¸ê®Æ®wªºProviders¡A±z¥i¥H±qMicrosoft webºô¯¸,¤U¸ü¨ä¥LOLE DB Providers¡A§Ú¤]´¿¸gÅ¥»D±q²Ä¤TªÌ¨ó¤O¼t°Ó´£¨Ñ¨ä¥LªºOLE DB Providers¡C

¦bÂà´«ODBC¨ìOLE DB¥@¬É¤§¶¡¡A±z¥i¥H¨Ï¥Î¤@­Ó¯S§OªºOLE DB Provider¡A¦W¥sMSDASQL—¥Ñ¥¦¥N¬°³B²z¡A¥¦ªº¤u§@¦p¤@®y¾ô³s±µ¨ì¥ô¦óODBC¨Ó·½¡C¥N´Àª½±µ¦a³s±µ¨ì¸ê®Æ®w¡A±z¥i¥H¨Ï¥Î¯S©wªºProvider³s±µ¨ì¤@­ÓODBCÅX°Êµ{¦¡¹ï¸ê®Æ®wÂഫŪ¼g¸ê®Æ¡C³o­Óªþ¥[¼h¦³¤@­Ó®Ä¯àHit¡]Performace Hit¡^¡C·íµM±zÀ³¸Ó¥u·|¦b¦³§ó¦hªºProvider¥i¥H¿ï¾Ü®É¡A®³¨Ó­n·í§@¸Ñ¨M°ÝÃD®Éªº¤@­Óµu´Á¸Ñ¨M¤è®×¤~·|¬Ý¥¦¡C

ADO
¡@

ADO¬O¨ìOLE DB°ª¶¥ªº¤¶­±¡C¦³ÂI¹³¬O·í®ÉRDO©MODBC API¤@¼Ëªº¨¤¦â¡C´N¹³ODBC API¡AOLE DB¬O¤@­Ó§C¶¥¤¶­±¡A¤£¯à®e©ö¦a (©Î¥þµM)³Q°ª¶¥ªº»y¨¥¦s¨ú¡A½Ñ¦p¡GVisual Basic¡CADO«Ø³y¦bOLE DB¤§¤W¡A¥Î¨Ó´£¨ÑOLE DB©Î±N³y¦¨ÄY±Kªº»Ý¨D¡A¦ÒÅç¤@¦ìµ{¦¡³]­p®v¼¶¼g¨º¨Ç«D¥ß§Y¥i±oªº¥\¯à®Éªº¥»»â¡CADO¯à°÷§@¨ìRDO©Ò¤£¯à°µ¨ìªº»Ý¨D:¯à¨Ï¥Î«D¦P¨Bªº¬d¸ß©M³s½u¤Î¼ÖÆ[ªº§å¦¸§ó·s¡CADO¥[¤J«Ü¦nªº·s¯S¦â¡A¨Ò¦p¡GÀÉ®×°ò¦¡]file-based¡^©M¿W¥ßªºRecordsets¡B¶¥¼hªºRecordsets¡AÁÙ¦³«Ü¦h«Ü¦h...¡C

ADO³Ì­«­nªº¤@­Ó¯S¦â©Î³\¬O¥¦ªº©µ®i©Ê¡A¥N´À§@¬°¤@­Ó½Æ¦Xª«©M³æ´¹Å骺¼h¦¸¡A´N¹³DAO©MRDO¡AADO¥Ñ§ó¤Öª«¥ó²Õ¦¨¡A¦ý¬O¥i¥H¦³§ó¦h¤èªk³Qµ²¦X¡C¦b¯S§OªºOLE DB´£¨ÑªÌªºªí³æ¥i¥H¥[ADO¶i¥h¡A¹³¬O¡GMSDataShape´£¨ÑªÌ¡A´£¨Ñ¶¥¼hªºRecordset¨ì¨ä¥L´£¨ÑªÌ¡CMicrosoft¤]¦P®É»s³y·sªº¥\¯à¥i¥Î¦bADO©ó¶}©ñ¦¡µ{¦¡®wªº§Î¦¡°ÊºA³sµ²¨ì®Ö¤ßADOµ{¦¡®w¡C¨Ò¦p¡A·sªºADO2.1µ{¦¡®w¥]§t¤ä´©¸ê®Æ©w¸q»y¨¥©M¦w¥þ©Ê(¨º­Ó¬O«ü¡A«Ø¥ß·sªº¸ê®Æ®wªí®æ¡B¨Ï¥ÎªÌ©M¸s²Õªº¨Ï¥ÎªÌ)¡AJet¼Q®g¤ÞÀº½Æ»s¡A©M¦hºûªºRecordsets¡C¦]¬°³o¨Çªþ¥[¥\¯à¬O¤£¦Pªºµ{¦¡®w¡A°²¦p±zªºÀ³¥Îµ{¦¡¤£¨Ï¥Î¥¦­Ì¡A±z´N¤£¥²¤Àµo¥¦­Ì¡CDAO»PRDOªº¹ï¤ñ¡A¤À§O¥]§t¤@­Ó§ó¤j¤º´OªºDLL(Áa¨Ï±z¨Ï¥Î¤@­Ó«Ü¤p³¡¤À¥\¯à¡A¤´¥²¶·¤Àµo¥¦¥þ³¡ªºDLL)¡C

ADO¥t¥~ªº¤@­Ó¯S¦â¬O¡G±z¯à¨Ï¥Î¥¦¦b©ó¤@­ÓÂsÄý¾¹ªºHTML­¶­±¤§¤º¡A¦p¡GInternet Explorer©ÎªÌ¦b¤@­Ó¦øªA¾¹¤ä´©IISªºASP¡CADOªº¤@­Ó¦¸¨t²Î¡A¦W¥s»·ºÝ¸ê®ÆªA°Èµ{¦¡¡A¬Æ¦Ü¥iÅý±z°e¤@§å°O¿ý¨ì»·ºÝªº«È¤áºÝÂsÄý¾¹©ÎªÌ¶V¹Lºô»Úºô¸ô±Ò°ÊCOM¤¸¥ó¡C

ADO°ß¤@ªºªº¯Ê³´¬O¡A¥¦¬O¤@­Ó©|¥¼À³¥Î¦b¯u¹ê¥@¬É¤¤¡A´ú¸Õ¹L¥¦ªºÃ­©w©Êªºªñ¨Ó§Þ³N¡A¥u¦³DAO©MRDO¦³¡CÄ´¦p¡Aµ§ªÌµo²{ADO 2¤¤¦³¤@¨Ç°ÝÃD¡A®Ú¾Úµ§ªÌªº¸gÅç¤j¦h¼Æªº°ÝÃD¬O¥Ñ©óOLE DB´£¨ÑªÌ³y¦¨¡A¨Ã«DADO¦Û¤vªº°ÝÃD¡C³o°ÝÃDªº¨ä¤¤®t²§¬O­«­nªº¡G¦]¬°±z³q±`¥i¥H¦b¤@­Ó·sªºª©¥»³QÄÀ¥X®É¡A¸g¥Ñ²³æªº¾A®É§ó·s´£¨ÑªÌ­×¥¿³o¨Ç°ÝÃD¡C¨Æ¹ê¤W¡Aµ§ªÌµo²{³o¨Ç¬°Microsoft Jet 4.0¤ÞÀº©MSQL Server 7.0ªº´£¨ÑªÌ¤ñª©¥»Jet 3.51¤ÞÀº©MSQL Server 6.5.§ó¦n(³Ì·sªº´£¨ÑªÌ©MVisual Basic 6¤@°_´²µo¥X¨Ó¡C)§Æ±æ¡A¦b±zŪ³o¥»®Ñªº®É­Ô¤§«e¤j³¡¥÷ADO¥D­nªº°ÝÃD¡A¤w¸g³£³Q§ï¦n¡C¦b¥t¤@¤è­±¡A°ß¤@¹ïADO¨ú¥Nªº¿ï¾Ü¤è®×¬OÄ~Äò¨Ï¥ÎDAO©ÎªÌRDO¡A¦ý¬O¡A¦pµ§ªÌ¤w¸g»¡©úªº¡A³o¨Ç§Þ³N¦b¥¼¨Ó±N¤£·|ÅãµÛ¦a§ïµ½¥¦­Ì¡C¥H¤W±z¥i¥H¤F¸Ñ¨ì¿ï¾Ü¨Ï¥Î¸ê®Æ¦s¨ú§Þ¥©¬O¤@­Ó½ÆÂøªº¨Æ¡C§ÚªºÂ²³æ«Øij¬O¡A¦pªG±z¥¿¦bºûÅ@©Î§ó·s¤@­Ó¤w¬[ºc¦bDAO©ÎRDOªºÀ³¥Î¨t²Î¡]©ÎODBC APIs¡Ð¦pªG±z¬O¤@¦ì«i´±ªºµ{¦¡³]­p®vªº¸Ü)¡A±z´N¬ÝµÛADO¥¼¨Óªº¨«¦V¡F¦pªG±z¥¿¶}©l¤@­Ó·sªºÀ³¥Îµ{¦¡¨t²Î¡Aµ¹ADO¤@­Ó¹Á¸Õ¾÷·|§a¡A°²¦p±z­p¹º¥h§ó·s©MºûÅ@¥¦¦h¦~¡A©ÎªÌ¦pªG­p¹º³Ì«á·|±N¥¦©ñ¨ì¨ìºô»Úºô¸ô¤W¡C

¦n®ø®§¬OVisual Basic 6¥]§t¤@¨Ç¤u¨ã©M³]³Æ¥i¨³³t¦a©M¦³®Ä¦a«Ø¥ßADOÀ³¥Îµ{¦¡¡C¬°¦¹½t¬G¡A³o¥»®ÑªºµJÂI±Mªù¶°¤¤¦bADO¡C

µøıªº¸ê®Æ®w¤u¨ã
¡@

Visual Basic 5¥ø·~ª©¥»¬O²Ä¤@­Ó¦bIDE¤§¤º¾ã¦X¤@®M¸ê®Æ®w¤u¨ãªº»y¨¥ª©¥»¡C

¦b¨º¤§«e¡A±z¥²¶·Âà´«¨ì¥t¤@­Ó¥~³¡µ{¦¡¡A¨Ò¦p¡G¤£ºÞ±z»Ý­n«Ø¥ß©Î½s¿è¤@­Ó¸ê®Æªí¡B³]©w¨â­Ó¸ê®ÆªíªºÃöÁp¡B³]­p¤@­Ó¬d¸ßµ¥µ¥¡D¡D³£­n¨Ï¥ÎSQL Server Enterprise Manager¡]SQL ServerªººÞ²zµ{¦¡¡^¡A©Î¬OFoxPro¡C¦bVisual Basic 6¤§«á¡A¤j¦h¼Æªºµøı¤Æ¸ê®Æ®w¤u¨ã²Õ¤]ªþ¦b±M·~ªºª©¥»¤§¤º¡C·sª©¥»ªºµøı¤Æ¸ê®Æ®w¤u¨ã¬O§ó¦nªº¾ã¦XÀô¹Ò¡A¦bIDE¤¤ªº¤@¨Ç¿ï³æ¡Ð§óÅãµÛªº¬d¸ß¥\¯àªí¡B¹Ï¥Ü¥\¯àªí¡B©M¦bÀɮסB½s¿è©MÆ[¬Ýªº¤@¨Ç©R¥O¡Ð·íµøı¤Æ¸ê®Æ®w¤u¨ãªºµøµ¡Àò±oµJÂI®É´N·|Åܦ¨¥i¥Îªº¡C

¦b³o¸`¸Ì¡A§Ú­Ì¨ÓÂsÄý³o¨Ç¤u¨ã©M®i¥Ü¦p¦ó¨Ï¥Î¥¦­Ì¨ÓºÞ²z±zªº¸ê®Æ®w¡C½Ð°O¦í¡A¸ê®Æ®w³]­p®vµøµ¡¤Î¬d¸ß³]­p®vµøµ¡¥u¦³¦bVisual Basic 6¥ø·~ª©¥»¤~¥i¥H¥Î¡C

¸ê®ÆÀ˵øµøµ¡
¡@

¨Ï¥Îµøı¤Æ¸ê®Æ®w¤u¨ãªº²Ä¤@¨B´N¬O¡u¸ê®ÆÀ˵øµøµ¡¡v¡A±z¥i¥H¦b À˵ø ¥\¯àªí¤¤ÂI¤@¤U ¸ê®ÆÀ˵øµøµ¡ ©Î¬O«ö¤U¼Ð·Ç¤u¨ã¦C¤¤ªº¶À¦â¹Ï¥Ü¨ÓÅã¥Ü¥¦¡A³o­Óµøµ¡¤¤¦sµÛ©Ò¦³¹ï¸ê®Æ®wªºConnection¡FConnection¥s°µ¸ê®Æ³sµ²¡A¨Ò¦p¡G¡u¸ê®ÆÀ˵øµøµ¡¡v¦b¹Ï8-4¥]§tµÛBiblio¤ÎNwind¼Q®g¤ÞÀº¸ê®Æ®w©M¨â­ÓConnection¡A¤@­Ó¬O¨Ï¥ÎNative OLE DB Provider for SQL Server¨ìSQL Server¸ê®Æ®wªºPubs¸ê®Æªí¡A¥t¤@­Ó¬O¨Ï¥ÎMSDASQL Provider for ODBC¡A±z¥i¥H¶}±Ò³o¨Ç¸ê®Æ³sµ²ÂI©MÅã¥Ü©Ò¦³¦b¸ê®Æ®w¤¤ªº¸ê®Æªí¡BÀ˵øªí¡B¸ê®Æ®w¹Ïªí¡A¤Î¹w¦sµ{§Ç¡]¦bOracle¸ê®Æ®w¤¤¡A±z¥i¥H¦h¬Ý¨ì¨â­Ó¤å¥ó§¨¡AFunctions and Synonyms¡C¡^±z¥i¥H®i¶}¤@­Ó¸ê®Æªí©Î¬O¤@­Ó¸ê®Æ®w¹Ïªí¸`ÂI¨Ó¬Ý¦U­Ó¸ê®Æªí©Î¬O¸ê®Æ®w¹Ïªí¸ÌÄæ¦ìªº¸Ô²Ó¸ê®Æ¡A¤]¥i¥H¥Î¥k·Æ¹«Áä¦bÄÝ©Ê¥\¯àªí¤¤¬Ý¦U­Óª«¥óªºÄÝ©Ê¡CÅý§Ú²³æ§ã­nªº»¡©ú¦b¸ê®ÆÀ˵øµøµ¡¤¤±z¥i¥H°µ¤°»ò¡G


¡@

¹Ï8-4 Åã¥Ü¦b¸ê®ÆÀ˵øµøµ¡¤¤ªºª«¥ó¥i¥H¥ÎÄݩʹï¸Ü²°Åã¥Üª«¥óªºÄÝ©Ê


¡@

¹Ï8-5 ¦p¦Pµøı¸ê®Æ®w¤u¨ã¤¤¤@¼Ëªº¸ê®Æªí¤º®e

Ãö©ó¥H¤W³o¨Ç¥\¯à¡A¦³¤@¨Ç¬O¸û­«­nªº­È±o¸û¸Ô²Óªº»¡©ú¡C

·s¼W¤@­Ó¸ê®Æ³sµ²
¡@

¦b¨Ï¥Î¸ê®ÆÂsÄýµøµ¡¤§«e¡A±z¥²¶·½T©w«Ø¥ß¤@­Ó¸ê®Æ³sµ²¨ì¸ê®Æ®w¡A¤@­Ó¸ê®Æ³sµ²¥]§t¤@¨Ç¸ê°T¡A¦p±z·Q³s±µ¨ì¸ê®Æ®wªº¸ê®Æ®w¤ÞÀºOLE DB providerªº¦W¦r©M¨ä¥Lµn¤Jªº¸ê®Æ¦p©m¦W©M±K½X¡C


¡@

¹Ï8-6 ·Q­n«Ø¥ß¤@­Ó·sªº¸ê®Æ³sµ²¡A±z¥²¶·­n¿ï¾Ü¤@­ÓOLE DB provider¡C

±z¥i¥H«Ø¥ß¤@­Ó·sªº¸ê®Æ®w³sµ²¦b¸ê®ÆÀ˵ø¤u¨ã¦C¤W³Ì¥kÃ䪺¹Ï¥ÜÂI¤@¤U©Î¬O¦b¸ê®Æ®w³sµ²ªº¤å¥ó§¨¤W¥kÀ»·Æ¹«Áä¦AÂI¿ï¼u¥X¥\¯àªíªº ·s¼W¸ê®Æ³sµ² ¡C³o­Ó©R¥O·|±Ò°Ê¤@­Ó¥|¨BÆJªººëÆF¡A²Ä¤@­¶½Ð°Ñ¦Ò¹Ï8-6¡C¦b³o¤@­¶¤¤±z¥i¥H¿ï¾Ü±z·Q­n³s±µ¸ê®Æ®wªºOLE DB provider¡A¤º©w­ÈADO¨Ï¥ÎMicrosoft OLE DB Provider for ODBC Drivers (MSDASQL)¡A³o¤@­ÓProvider¹ê»Ú¤W´X¥G¥i¥HÅý±z³s±µ¥@¬É¤W©Ò¦³ªºÃöÁp¦¡¸ê®Æ®w©MISAM¸ê®Æ®w¡C¹ï©ó¦³¨Ç¸ê®Æ¨Ó·½¡A±z¤]¥i¥H¨Ï¥Î®Ä¯à¤ñ¸û¦nªº©M¤ñ¸û¦h¯SÂIªºProvider¡A¨Ó¦]À³¯S§Oªº¸ê®Æ®w³s±µ¡C

²Ä¤G­¶ªººëÆFªº¤º®e¨ú¨M©ó±z¿ï¾ÜªºProvider¡A¨Ò¦p·í³s±µ¨ìJet¸ê®Æ®w±z¥u»Ý¿ï¾Üªþ¥[ÀɦWMDBªºÀɮ׸ô®|©M¨Ï¥ÎªÌªº©m¦W¤Î±K½X¡C¹Ï8-7®i¥Ü·í±z³s¨ìSQL Server 6.5¨Ï¥ÎMicrosoft OLE DB Provider for SQL Server 6.5¸ê®Æ®wªº¿ï¶µ¡G¦b³o¸Ì±z¥²¶·¿ï¾Ü¥D¾÷ªº¦WºÙ¡A¿é¤Jµn¤Jªº¸ê®Æ¡A¦pªG±z­nªº¸ÜÁÙ¥i¥H¿é¤J¸ê®Æ®wªº¦W¦r¡A¡]³o¬OADO©ÒºÙªº°_©l¥Ø¿ý¡^½Ð°O¦í¦pªG±z¾A¥ÎªÅ¥Õªº±K½X¡A´N­n¤Ä¿ïªÅ¥Õ±K½Xªº¿ï¶µ¦]¬°Åý±K½XÄæ¦ì¬°ªÅ¥Õ·|¤£¯à°Ê§@¡C¦pªG±z¬O¥Î ¨Ï¥ÎWindows NT¾ã¦X¦w¥þ ±z´N¤£¥Î«ü©w¨Ï¥ÎªÌªº¦WºÙ¤Î±K½X¡A¦b³o­Ó±¡ªp¤U¡ASQL Server¨Ï¥Î±zµn¤Jºô°ìªº¨Ï¥ÎªÌ©M±K½X¨ÓÀˬd±z¬O§_¦³³Q¤¹³\¦s¨ú¥D¾÷¡A«ö¤U´ú¸Õ³s±µ¥i¥H½T©w¥þ³¡³£¨S¦³°ÝÃD¡C


¡@

¹Ï8-7 Microsoft OLE DB Provider for SQL Serverªº³s±µÄÝ©Ê

·í±z¥Î¤º©wªºOLE DB Provider for ODBC Drivers¡AºëÆFªº²Ä¤G­¶´N¤£¦P¤F¡A¦b³o­Ó®×¨Ò¤¤¡A±z¥i¥H¿ï¾Ü¤@­ÓDSN©Î¬O¨Ï¥Î¤@­Ó³s±µ¦r¦ê¡]¤j²¤ªº´y­z²Å¦X¤@­ÓµLDSN³s±µ¡^¡A¦pªG±z¬O¿ï¾Ü¨Ï¥Î³s±µ¦r¦ê¥i¥H±q¤w¦s¦bªºDSN¶}©l«Ø¥ß©Î¬OÀH·Nªº¦Û¤v«Ø¥ß¡A±z¤]¥i¥H¨Ì·Ó±z¨Ï¥ÎªºODBCÅX°Êµ{¦¡¨Ó­×§ï¨äÄÝ©Ê¡C¦pªG±z¶ñ¤J¨Ï¥ÎªÌ¤Î±K½X©M¨Ï¥Îªºªì©l¥Ø¿ý (½Ð¬Ý¹Ï8-8)¡A±z´N¤£¥Î¦bºëÆF¤¤¦A¿é¤J¤@¦¸¤F¡]¹Ï8-8ªº¥ª¤è¡^¡C


¡@

¹Ï8-8 «Ø¥ß¤@­Ó³s±µ¦r¦ê¡C

¦b¸ê®Æ®w³s±µºëÆF¤¤³Ñ¤Uªº¨â­¶³q±`¤£·|»Ý­n¥h¿é¤J¥ô¦óªº¸ê®Æ¡A¦ý¬O¦pªG¦b¶i¶¥­¶ÅÒ¤¤³]©w¶}±Ò¸ê®Æ®wªº¤è¦¡¬°read-only§@·~¿W¥e¤è¦¡·|¨Ï±zªºÀ³¥Îµ{¦¡¦b³Ì¨Î¤Æ¤W±o¨ì§ó°ªªº°õ¦æ³t«×¡A±z¤]¥i¥H³]©w§ó°ªªº³s±µ¹O®É®É¶¡¥H¨¾¤î¹O®Éªº¿ù»~µo¥Í¡C¦bºëÆFªº³Ì«á¤@­¶©R¦W¬°¥þ³¡¡A±z¥i¥H¬Ý¨ì©Ò¦³«e´X­¶²£¥ÍªºÄÝ©Ê¡A©Ò¦³¨ä¥L¥i­×§ïªºÄݩʳ£¥i¥H¦b³o¸Ì­×§ï¡C¤@¯ë¨Ó»¡¡A³o¨Ç¬O¶i¶¥ªº³]©w¡A±z¤£¥Î¥h§ó°Ê¥¦ªº¹w³]­È¡A¦]¬°¨C­ÓOLE DB provider¦C¥XªºÄݩʳ£¤£¦P¡A±zÀ³¸Ó°Ñ¦Ò³o¨ÇÅX°Êµ{¦¡ªºªþ¥[¤å¥ó¨Ó±oª¾§ó¦hªº¸ê°T¡C


¤p¯µ³Z

¦pªG±z¨Ï¥ÎMicrosoft OLE DB Provider for SQL Server 6.5¡A±z·|¤£¯à¦C¥X±z©Òµ¹¤©ªºSQL Server¤¤¥]§tªº¸ê®Æ®w¡A³o¦n¹³¬O³o­Óª©¥»ªºbug¡A¨Æ¹ê¤W¥u­n¤É¯Å¨ìMicrosoft OLE DB Provider for SQL Server 7.0¡A³o¨Ç°ÝÃD³£·|¸Ñ¨M¡C¡]±z¥u»Ý­n¤É¯Åprovider¡A¤£¥Î³sSQL Server¤ÞÀº¤]¤É¯Å¡^¡CSQL Server 6.5¥u»Ý­n§Ú­Ì¤@ÂI¤p°Ê§@´N¥i¥H¸Ñ¨M³o­Ó°ÝÃD¡A¥ý§ä¨ì¦b±z¨t²Î¤¤ªºINSTCAT.SQL³o­ÓÀÉ¡A¡]±zÀ³¸Ó·|¦b\Windows\System³o­Ó¥Ø¿ý¤¤§ä¨ì¡^µM«á¦bISQL_w¸ü¤J³o­ÓÀɮשM°õ¦æ³o­Ó´y­zÀÉ¡F·í°õ¦æ§¹®É¡A¦A¸Õ¤@¦¸«Ø¥ß¸ê®Æ³sµ²¡A±z±Nµo²{¥i¥H¥¿½Tªº¦C¥X©Ò¦³SQL Serverªº¸ê®Æ®w¡C


«Ø¥ß©Î­×§ï¤@­Ó¸ê®Æªí
¡@

¦b¤@­Ó¤w¦s¦bªº¸ê®Æªí¤W³æÀ»¥k·Æ¹«ÁäµM«á¦b¼u¥X¥\¯àªí¤W¿ï¾Ü ·s¸ê®Æªí ´N¥i¥H·s¼W¤@­Ó¸ê®Æªí¡C¥¦·|°Ý±z·s¸ê®Æªíªº¦W¦r¡A¦p¹Ï8-9¡A±z¥²¶·Áä¤J¦b³o­Óµøµ¡¤¤©Ò¦³Äæ¦ìªº¦W¦r©M¥L­Ìªº¸ê®Æ«¬ºA¡]¾ã¼Æ¡A¯BÂI¤p¼Æ¡A¦r¦ê¡Aµ¥µ¥.....¡^¡Aªø«×¡Aºë½T«×©MÄæ¦ìªº¹w³]­È¡A±z¤]¥²¶·¨M©w­þ¨ÇÄæ¦ì¥i¥H±µ¨üNull©M¨º¨ÇÄæ¦ì¬O¸ê®Æªí¤¤ÃѧOªºÁä­È¡C


¤p¯µ³Z

·í±z«Ø¥ß¤@­Ó¸ê®Æªí¡A±z¥i¥H±q¨ä¥L¦b¸ê®Æ®w¤¤ªº¸ê®Æªí¨Ï¥Î½Æ»s¤Î¶K¤W¨Ó«Ø¥ß·sÄæ¦ìªºÄÝ©Ê¡A¦pªG­n¿ï¾Ü¦h­ÓÄæ¦ì¡A¥i¥H«ö¦íCtrl©ÎShiftÁä¦AÂI¿ï±z­n½Æ»sªºÄæ¦ì¡A³o®ÉÄæ¦ì·|Åܦ¨¤Ï¥Õ¡]¹Ï8-9¡^±z¥i¥H¨Ï¥Î²Õ¦XÁäCtrl+C¨Ó§@½Æ»s¡AµM«á¥ÎCtrl+V¨Ó§@¶K¤W.ªº°Ê§@¡C



¡@

¹Ï8-9 ·í±z«Ø¥ß¤@­Ó·sªºªí®æ©Î­×§ï¤w¦s¦bªºªí®æ¡A±z¥i¥H±q¨ä¥Lªºªí®æ½Æ»s©M¶K¤WÄæ¦ìÄÝ©Ê¡C

¤U¤@­Ó¨BÆJ¬O¨M©w¨º­ÓÄæ¦ì¡]©Î¬O­þ¨ÇÄæ¦ì¡^­n¦¨¬°¥D­n¯Á¤ÞÁä¡A¦pªG»Ý­n¥i¥H¨Ï¥Î¦h­ÓÄæ¦ì·í¥D­n¯Á¤ÞÁä¡]«ö¦íCtrl©ÎShift¥[¤W³æÀ»¥ª·Æ¹«Áä¿ï¨ú¡^¡A¥D­n¯Á¤ÞÁä¥Î¦bªí®æ¤¤ÃѧO°O¿ý¬O§_¬°°ß¤@ªº¤@µ§°O¿ý©M¥Î¨Ó·í§@ÃöÁpªº³W«h¬O¬Û·í¦³¥Îªº¡A³q±`±z¤]·|»Ý­n¥D­n¯Á¤ÞÁä¨Ó«Ø¥ß¥i¥H¦b¸ê®Æªí¤¤¥i¥H§ó·sªº«ü¼Ð¡A¨C¤@­Ó¸ê®Æªí¤¤¥u¥i¥H«Ø¥ß¤@­Ó¥D­n¯Á¤ÞÁä¡A¦Ó¥B¥]§tªºÄæ¦ì¤£¥i¥H¦³Null­È¡A·í±z«Ø¥ß¦n¤F¤§«á¦b¸ê®Æªíªº¥ª¤è·|¦³Æ_°Íªº¹Ï¥Ü¥X²{¡C

¦pªG±z¦b®æ½u¤¤³æÀ»¥k·Æ¹«Áä¦b¿ï¾Ü¥\¯àªí¤WªºÄÝ©Ê©R¥O¡A·|¥X²{¹³¹Ï8-10ªºµe­±¡C¦b³o¸Ì±z¥i¥H©w¸q­­¨î±ø¥ó¡BÃöÁp©Ê©M³o­Ó¸ê®Æªíªº¯Á¤Þ¡C

­­¨î±ø¥ó´N¬O¦b¸ê®Æªí¤¤¤@­Ó©Î¦h­ÓÄæ¦ì²³æªº§PÂ_ÅçÃÒªº³W«h¡A¨Ò¦p¡G

price > 0

¤@­Ó¸ê®Æªí¥i¥H¦³¦h­Ó­­¨î±ø¥ó¡A¨C¤@­Ó­­¨î±ø¥ó³£¦³¤@­Ó¦W¦r¡A±z¥i¥H¹ï¨C­Ó¤w¦s¦b¸ê®Æªí¤¤ªº¸ê®Æ¿ý³]©w­­¨î±ø¥ó¡A¬°©Ò¦³«á¨Ó©Ò§@ªº·s¼W/§R°£°Ê§@§@­­¨î¡C

Äݩʪº²Ä¤G­¶¤¤¥i¥H­q©w³o­Ó¸ê®ÆªíªºÃöÁp©Ê¡C

Äݩʪº²Ä¤T­¶¹ï¸Ü²°¡A±z¥i¥H«Ø¥ß©M§R°£³o­Ó¸ê®Æªíªº¯Á¤Þ¡C¦pªG±zª¾¹D¤@­Ó©Î¬O¦h­ÓÄæ¦ìªº­È¡A¯Á¤ÞÅý±z¥i¥H§Ö³t¨ú±o¸ê®Æªí¤¤ªº¸ê®Æ¡C¯Á¤Þ¤]¥i¥HÅý±z«Ø¥ß¸ê®Æªí¤§¶¡ªºÃöÁp©Ê¨Ï¸ê®Æªº§¹¾ã¤£³Q¯}Ãa¡A±z¥i¥H©w¸q¦hºØ¤£¦Pªº¯Á¤Þ¡A ¥D­n¯Á¤ÞÁä ¬O¸ê®Æ®wªº¥D­n¯Á¤Þ¡F¥¦­Ìªº¤º®e¬O¤£¯à¬°Null¥B¬O°ß¤@ªº¡A©Ò¥H¥i¥H·í§@¸ê®Æªí¤¤°ß¤@¤@µ§ªº½T»{¡C ¥~³¡¯Á¤ÞÁä ¡]foreign key index¡^¬O«ü¨ä¥L¸ê®Æªí¤¤ªº¤@­Ó©Î¦h­ÓÄæ¦ì·í¯Á¤ÞÁä¡A±`³Q¥Î¦b·í¨â­Ó¸ê®Æªí¤§¶¡¦³¤@ºØ¦@¨ÉªºÃöÁp©Ê®É¡C °ß¤@ªº¯Á¤ÞÁä ¬O¥Ñ¥ô·NªºÄæ¦ì¡]©Î¬OÄæ¦ì²Õ¦X¡^¦¨¬°¸ê®Æªí¤¤ªº°ß¤@ªº¤@µ§¡A ©M¥D­n¯Á¤ÞÁ䤣¦Pªº¬O¥¦¥i¥H±µ¨üNull­È¡C±z¤]¥i¥H«Ø¥ß¤@ºØ«D°ß¤@ªº¯Á¤Þ¡A¥D­nªº¥Î³~¤j¦h¬O¥Î¨Ó´£ª@·j´M³t«×¡A¤@¨Ç¸ê®Æ®w¤ÞÀº¤]¤ä´©ÂO¶°¯Á¤Þ¡A¥Î¨Ó½T©w¸ê®Æ¦b¹êÅ骺¸ê®Æªí¤¤ªº±Æ¦C¬O©M¯Á¤Þ±Æ§Ç¬O¤@¼Ëªº¡]¨C¤@­Ó¸ê®Æªí¥u¯à¦³¤@­Ó³o¼Ëªº¯Á¤Þ¡^¡C


¡@

¹Ï8-10 ±z¥i¥H¦b¸ê®ÆªíªºÄÝ©Ê­¶¤¤«Ø¥ß¤@­Ó±ø¥ó¡C

·í±z§¹¦¨©Î¬O½Õ¾ã¤F¸ê®Æªí¡A±z¥i¥H¿ï¾ÜÀx¦s§ó§ï¸ê®Æªíªº´y­zÀɮסA¨ä¤¤¥]§t¤F±z©Ò§@ªºÅܧó¥i¥H´£¨Ñ¤U¦¸­«·s«Ø¥ß¸ê®Æªí®Éªº°Ñ¦Ò¡C¨Ò¦p¡G¦bµ§ªÌªº¨t²Î¤¤©Ò¦³ªº´y­zÀɳ£¦s¦bC:\Program Files\Microsoft Visual Studio\Vb98ªº¥Ø¿ý¤U¡C

¸ê®Æ®w¹Ïªíµøµ¡
¡@

¦p¦Pµy¦­´£¹Lªº¡A¸ê®Æ®w¹ÏªíÅã¥Ü¸ê®Æ®w¤¤©Ò¦³©Î³¡¤À¸ê®ÆªíªºÄæ¦ì©M¯Á¤ÞÁä¡A©M¥¦­Ì¤§¶¡ªºÃöÁp©Ê¡A§Ú­Ì¥i¥H¦b¸ê®ÆÀ˵øµøµ¡ªº¸ê®Æ®w¹Ïªí¤W¥kÀ»·Æ¹«Áä¦A¿ï¾Ü·s¼W¹Ïªíªº©R¥O¨Ó±a¥X¸ê®Æ®w¹Ïªíµøµ¡¡A¥t¥~¦bµøı¤Æ¸ê®Æ®w¤u¨ã±z¥i¥H±q¸ê®ÆÀ˵øµøµ¡©ì¦²¸ê®Æ®w¨ì¸ê®Æ®w¹Ïªíµøµ¡¡A·í©ñ¸m¤F¦h­Ó¸ê®Æªí«á¡A¦U­Ó¸ê®Æªí¤§¶¡ªºÃöÁp©Ê´N·|Åã¥Ü¥X¨Ó¡A±z¤]¥i¥H¥Î¥k·Æ¹«ÁäÂI¤@¤Uµøµ¡¤¤ªº¸ê®ÆªíµM«á¿ï¾Ü ·s¼WÃöÁpªº¸ê®Æªí ©R¥O¨ÓÅã¥Ü¦³ÃöÁpªº¸ê®Æªí¡A¹Ï8-11®i¥Ü¤F¦bSQL Server¤WªºPubs¸ê®Æ®w¡A¦b¹Ïªíµøµ¡¤¤±z¥i¥H§¹¦¨¡G

¦b¨â­Ó¸ê®Æªí¤§¶¡ªºÃöÁp©Ê¬O¤@­Ó¸ê®Æ®w³]­pªº­«­n¤§¤@¡C±z¥i¥H©ñ¸m¸ê®Æªí¬°¤@¹ï¤@ªºÃöÁp¡A©Î¬O¤@¹ï¦hªºÃöÁp¡A¨Ò¦p¡GPubs¸ê®Æ®w¤¤ªºPusloishers©MPub_info¸ê®Æªí´N¬O¤@­Ó¤@¹ï¤@ªºÃöÁp¡F¦Ó¤@¹ï¦hªºÃöÁp´N¹³¬OPublishers©MTitles¸ê®Æªí¡A ±z¥i¥H¦b¸ê®Æ®w¹Ïªíµøµ¡¤¤¦b¨â­ÓÃöÁp¤§¶¡ªº½u¤W¥kÀ»·Æ¹«Áä¨Ã¿ï¨ú[ÄÝ©Ê]¥\¯àªí©R¥O¨Ó§ó§ïÃöÁpªºÄÝ©Ê¡C

¸ê®Æ®w¹Ïªíµøµ¡¤]¥i¥H¥Ñ­ì¦³ªº¹Ïªí¥Î©ì©ñªº¤è¦¡¨Ó§¹¦¨¡A¨Ò¦p¡G±z¥i¥Hcopy¤@³¡¥÷¹Ïªí¤¤ªº¸ê®Æ®w¦A©ì¦²¨ì¥t¤@­Ó¹Ïªíªºµøµ¡¤¤¡C³o¼Ë±z´N¥i¥H±N¦h­Ó¹Ïªí²Õ¦X¦¨¤@­Ó¤jªº¹Ïªí¡A³o­Ó§Þ¥©¦b±z³B²z¸ê®Æ®w¤¤§t¦³¤j¶qªº¸ê®Æªí®É¬Û·íªº¦³¥Î¡C


¡@

¹Ï8-11 ¦bPubs¸ê®Æ®w¤¤ªº¤@­Ó¸ê®Æ®w¹Ïªí¡C

¬d¸ß³]­p®vµøµ¡
¡@

¦pªG±z¦b¸ê®ÆÀ˵øµøµ¡¤¤¦bÀ˵øªí¤å¥ó§¨³æÀ»¥k·Æ¹«Áä¡A±z¥i¥H«Ø¥ß¤@­Ó·sªºÀ˵øªí¡AÀ˵øªí¬O±q¤@­Ó¸ê®Æªí¤¤©Î¬OÅ޿誺¨â­Ó©Î¦h­Ó¸ê®Æªíªº¸ê®Æ¿ý²Õ¦X¦Ó¦¨¡C¨Ò¦p¦bPubs¸ê®Æ®w¤¤ªºTitleviewÀ˵øªí¤@°_Åã¥Ü¥X©Ò¦³¦b¸ê®Æ®w¤¤ªºtitle©Mauthors¡A­n¨ú±o³o¨Ç¸ê°T¡A¥²»Ý±qAuthors,¡BTitles¡BTitlesAuthor.¤T­Ó¤£¦Pªº¸ê®Æªí¤¤»`¶°¸ê®Æ¡A·í±z«Ø¥ß¤@­Ó·sªº©Î¬O­×§ï¤@­ÓÀ˵øªí¡A¬d¸ß³]­p®vµøµ¡´N·|Åã¥Ü¥X¨Ó¡A³o¬O¥t¤@­Óµøı¤Æ¸ê®Æ®w¤u¨ã²Õ¤¤¤@­Ó¬Û·í¦³¥Îªº¦¨­û¦]¬°¥¦¯àÅý±z¨Ï¥Îª½Ä±¨Ï¥ÎªÌ¤¶­±«Ø¥ß¬d¸ß©MÀ˵øªí¡A¬d¸ß³]­p®vµøµ¡³Q¤À¦¨¥|­Óµ¡®æ¡A´N¦p¦P ¹Ï8-12 ©Ò¥Ü¡C


¡@

¹Ï8-12 ¦b¬d¸ß³]­p®v¶}±ÒPubs¸ê®Æ®w¤¤ªºTitleviewÀ˵øªí¡C

ADO¸ê®Æôµ²
¡@

²Ä¤@­ÓVisual Basic (ª©¥»3)©Ò¤ä´©ªº¸ê®Æ®wªí³æ¬OData±±¨î¶µ©Mµ²¦X±±¨î¶µ¡A¦p¦P§Ú¦b¦¹³¹²Ä1¬q©Ò¸ÑÄÀ¡C³oºØôµ²ªº¾÷¨î¦bVisual Basic 4©M5¤¤¤w¸g¸g¹L§ï¨}¡A¦ý¨Ã¨S¦³¤Ó¤jªº§ïÅÜ¡Aª½¨ìVisual Basic 6­º¦¸±À¥XADOôµ²¾÷¨î¬°¤î¡C

ôµ²¬O¤@ºØ§Þ³N¡AÅý§A±N±±¨î¶µ-¦pTextBox¡BCheckBox¡BListBox©MComboBox±±¨î¶µ-©ñ¸m¦bªí³æ¤W¨Ã±N©Ò¦³±±¨î¶µ»P¥t¤@­ÓºÙ°µDataªº±±¨î¶µ[ôµ²]¦b¤@°_¡AData±±¨î¶µ¦A»P¸ê®Æ®w³sµ²¡CData±±¨î¶µÅý§A¯à¦b¸ê®Æ®w¤¤¤Á´«°O¿ý¡G¨C¦¸·sªº°O¿ýÅܦ¨²{¦³°O¿ý®É¡A¥¦ªºÄæ¦ì­È´N·|»Pôµ²±±¨î¶µ¤¤Åã¥Ü¡C¦P¼Ëªº¡A¦pªG¨Ï¥ÎªÌ§ó·sôµ²±±¨î¶µªº­È¡A³o¨ÇÅܧó«K·|¶Ç¼½¨ì¸ê®Æ®w¤W¡C§A¥i¥H¤£¥Î¼¶¼g¤@¦æµ{¦¡½X«K¥i¥H«Ø¥ß¸ê®Æ®w¸ê®ÆªºÂ²³æ¨Ï¥ÎªÌ¤¶­±(³o¬O²z½×¡A¹ê»Ú¤W§AÀ³¸ÓÅçÃÒ¿é¤J¸ê®Æ¡A¨Ã®É±`±Nôµ²±±¨î¶µ©ÒÅã¥Üªº¸ê®Æ®M¥Î®æ¦¡)¡C

·sªºADOôµ²§Þ³N¹ï©óÅã¥Ü¸ê®Æ®w¸ê®Æªº¤è¦¡¦Ó¨¥¬O¤@ºØ­²·s¡C­º¥ý¡A§A¤£¥Î¤@ª½¨Ï¥Î¸ê®Æ®w¡A¦Ü¤Ö¤£¬Oª½±µ¡C¦bVisual Basic 6¤¤¡A§A¤£À³¸Ó½Í¨ìôµ²±±¨î¶µ©MData¸ê®Æ®w¡A§AÀ³¸Ó¦h¦h½Í½Í»P ¸ê®Æ¨Ó·½ Ã´µ²ªº++s¡C¦bVisual Basic 6¤¤¡A§A¥i¥H¨Ï¥Î³\¦hÃþ«¬ªº¸ê®Æ®ø¶OªÌ(Data Consumer)¡A¦p¤º«Ø©Î¥~³¡ªº±±¨î¶µ¡BÃþ§O¡BCOM¤¸¥ó¡B¦Û­qªºActiveX±±¨î¶µ(©ÎUserControl)¡B©ÎDataReport³]­p¤u¨ã¡C§A¤]¥i¥H¿ï¾Ü¥H¤Uªº¸ê®Æ¨Ó·½¡GADO Data±±¨î¶µ¡BÃþ§O¡BCOM¤¸¥ó¡BUserControl¡BDataEnvironment³]­p¤u¨ã(DataEnvironment³]­p¤u¨ã±N¦b¥»³¹µy«á°Q½×¡ADataReport³]­p¤u¨ã±N¦b ²Ä15³¹ °Q½×)¡C

¸ê®Æ¨Ó·½©M¸ê®Æ®ø¶OªÌªºÃþ§OÅý§A¦³µL¤ñªº¼u©Ê¯à¬°§AªºÀ³¥Îµ{¦¡³]­p³Ì¾A·íªºÃ´µ²¬[ºc¡A¥¦¤]¯à°÷©¿²¤­ì©lData±±¨î¶µ(¤ÎRemoteData±±¨î¶µ)³Ì¤jªº­­¨î¡C·í§A¨Ï¥ÎADOôµ²®É§A¨Ã¥¼»P2-Tierµ²ºc³sµ²¡A³o¬O¦]¬°§A¨S¦³¥²­n±N¨Ï¥ÎªÌ¤¶­±¤¸¯À»P¸ê®Æ®wªºÄæ¦ì³sµ²¡C§A¥i¥H¨Ï¥Î¦h­Ó¤¤¤¶COM¤¸¥ó¡A¦¹¤¸¥ó¹ê¦æ§ó¦³¼u©Êªº3-Tier³]­p¡C³o¨ÇCOM¤¸¥ó¦ì©ó¦ó³B¨Ã¤£¤Q¤À­«­n¡F¥¦­Ì¥i¥H¦b¥Î¤áºÝ¹q¸£¡B¦øªA¾¹¹q¸£©Î¨ä¥L¹q¸£¤W°õ¦æ¡C§A¥i¥H¦b¥Î¤áºÝ©M¦øªA¾¹¦b¦P¤@¥x¹q¸£¤W®É¶}µo3-Tier(ÁöµM¦b¦¹±¡ªp¤U§A½T©wµLªk§Q¥Î³\¦h3-Tier©Ó¿Õ)¡CN-Tierµ²ºcªº­«ÂI¬O«eºÝÀ³¥Îµ{¦¡¤£·|ºò±Kªº»P«áºÝ¸ê®Æ®wµ²¦X¡AÅý§A¯à°÷-¦pªG»Ý­nªº¸Ü-´À¥N«eºÝ©Î«áºÝ¦Ó¤£­n­«¼g¾ã­ÓÀ³¥Îµ{¦¡¡C

ôµ²¾÷¨î
¡@

·í±z±N¦h­Ó±±¨î¶µ»P¤@­ÓADO Data±±¨î¶µÃ´µ²®É¡A§A¥i¥H§Q¥Î³Ì²³æªºADOôµ²ªí³æ¡A¦ý§Ú¦b¦¹©Ò¸ÑÄÀªº·§©À¥i¥H®M¥Î¦b¥ô¦ó¤@ºØÃþ«¬ªº¸ê®Æ¨Ó·½©Î¸ê®Æ®ø¶OªÌ¤W¡C¦b ²Ä17 ©Î ²Ä18³¹ ¤º§A¥i¥H±oª¾§ó¦h¼¶¼g³oÃþ¸ê®Æ¨Ó·½©M¸ê®Æ®ø¶OªÌªº¸Ô²Ó¸ê°T¡C

¥Ñ©ó¨Ï¥ÎADO Data±±¨î¶µªº½t¬G¡A§A¥²¶·±N¥¦¥[¤J²{¦³ªº±M®×¤~¯à¦b±±¨î¶µªº ¤u¨ã½c ¤¤¨Ï¥Î¦¹±±¨î¶µ¡C§A¤]»Ý­n·s¼W¤@¨Ç¶µ¥Ø¨ì References ¹ï¸Ü¤è¶ô¤º¡A¤èªk¦p¤U¡G¿ï¾Ü ÀÉ®× ¥\¯àªí¤ºªº «Ø¥ß·s±M®× ¡A¥Ñ±M®×®w¤¤¶}±Ò Data Environment±M®× ½d¥»¡C¦¹½d¥»¯à¦b±M®×¤¤¥[¤J¼Æ­Ó¼Ò²Õ(¨ä¤¤¤@¨Ç¼Ò²Õ§Ú­Ì¦b¦¹¨Ã¤£°Q½×)¡A¦¹½d¥»¤]·|¥[¤JMicrosoft ActiveX Data Objects 2.0 Library (MSADO15.DLL)ªº°Ñ·Ó¨Ã¦b ¤u¨ã½c ¥[¤J¤@¨ÇÃB¥~ªº±±¨î¶µ¡A¥]¬AADO Data±±¨î¶µ¡C¦pªG§A¤w¸g¤É¯Å¨ì·sª©ªºADO 2.1¡A«h¥[¤J References ¹ï¸Ü¤è¶ôªº¶µ¥Ø¬Omsado20.tlb¡C

¦b±N ¤u¨ã½c ¤¤ªºADO Data±±¨î¶µ³]¸m¦b±M®×°ß¤@ªºªí³æfrmDataEnv¤W¡A¨Ã±N¥¦ªºAlignÄݩʳ]©w¬°2-vbAlignBottom¡AÅý¦¹±±¨î¶µ·|ÀHµÛªí³æ§ïÅܤj¤p¡C§A¥i¥H¥Ñ¤@¯ëªº ÄÝ©Ê µøµ¡¤¤³]©w¨ä¥LªºÄÝ©Ê¡A¦ý³Ì¦n¨Ï¥Î ÄÝ©Ê­¶ ¨Ó³]©w¡F ÄÝ©Ê­¶ ªº¶}±Ò¤è¦¡¬O¥H¥kÁä«ö¤@¤U¸Ó±±¨î¶µ¡A¨Ã¦b§Ö³t¥\¯àªí¤W¿ï¾Ü ADODCªºÄÝ©Ê ©R¥O¡C¦b ¤@¯ë ¼ÐÅÒ­¶¤¤¡A§A¥i¥H¨Ï¥Î¤TºØ¤èªk«ü©w§A­n³s±µ­þ¤@­Ó¸ê®Æ®w¡G¨Ï¥Î¸ê®Æ³sµ²ÀɮסB¨Ï¥ÎODBC¸ê®Æ¨Ó·½¦WºÙ(¦p§A©Ò¨£¡AªºDSN¦bADOªº¥@¬É¤¤¤´µM¦s¦b)¡B©Î¨Ï¥Î³s½u¦r¦ê¡C

 ¨Ï¥Î¸ê®Æ³sµ²ÀÉ®× »PÀɮ׬°°ò¦DSNªºADO¬Û¦P¡C°_ªì¡A§A¥i¯à¤£ª¾¹D­n¦p¦ó«Ø¥ß¤@­ÓUDLÀɮסA¦]¬°¨Ã¨S¦³¥ß§YÅã¥Ü New ©Î¬O Add ¶s¡Cµª®×¦b¹Ï8-13¤¤¡F«ö¤@¤U ÂsÄý ¶s¥H¶}±Ò ¿ï¾Ü¸ê®Æ³sµ²ÀÉ®× ¹ï¸Ü²°¡A¦¹¹ï¸Ü²°¯àÅý§AÂsÄý¦ÜUDLÀɮשҦbªº¥Ø¿ý¡C¥H¥kÁä«ö¤@¤U¹ï¸Ü¤è¶ô¤ºªºÀɮײM³æ(¥i¯à¬OªÅªº)¡A¿ï¾Ü ·s¼W ¡A¦A¿ï¾Ü Microsoft¸ê®Æ³sµ² ¡C¦p¦¹«K·|«Ø¥ß¤@­Ó"ªÅ¥Õ"ªºUDLÀÉ¡A§A¥i¥H±N¦¹ÀÉ®×­«·s¥H§A³ßÅwªº¦WºÙ©R¦W¡C¤@¥¹§Aª¾¹D°õ¦æªº¤èªk¡A¥¦´N¦¨¬°¤F¤@­Ó²³æªº¤u§@¡F¥u­n¤£­n±N¦¹µ{§ÇºÙ°µª½Ä±ªº¨Ï¥ÎªÌ¤¶­±¡C

«Ø¥ßUDLÀÉ®×¥u¬O¤u§@ªº¤@³¡¥÷¡A¦]¬°²{¦b§A¥²¶·«ü©w¸ê®Æ³sµ²ÀÉ®×­n«ü¦V­þ¤@­Ó¸ê®Æ®w¡C§A»Ý­n°õ¦æ¥t¤@­Ó§@·~¡G¥H¥kÁä«ö¤@¤U­è¤~§A«Ø¥ßªºUDLÀɮסA¨Ã¿ï¾Ü ¤º®e ©R¥O¡A«K·|¶}±Ò¤@­Ó¦³¦h±i¼ÐÅÒ­¶ªº ¤º®e ¹ï¸Ü¤è¶ô¡C¹ï¸Ü¤è¶ô¤¤³Ì«á¥|±i¼ÐÅÒ­¶¡G´£¨ÑªÌ¡B³s±µ¡B¶i¶¥¡B¥þ³¡¡A»P§A¦b ¸ê®ÆÀ˵ø µøµ¡¤¤«Ø¥ß¸ê®Æ³sµ²®É©Ò¬Ý¨ìªº¤@¼Ë¡F³o¨Ã¤£©_©Ç¡A¦]¬°¦b¦¹§Ú­Ì¤´¦b°Q½×¬Û¦Pªº·§©À¡C

§A¤]¥i¥H¤£¨Ï¥ÎUDLÀɮרê½±µ«Ø¥ß³s½u¦r¦ê¡C¦pªG§A«ö¤@¤UADODC ÄÝ©Ê­¶ ¹ï¸Ü¤è¶ô¤¤ªº «Ø¥ß ¶s¡A§A·|¦A¤@¦¸¬Ý¨ì¥iÅý§A©w¸qADO³s½uªº4±i¼ÐÅÒ­¶¡C§A¦b¨Ï¥Î ¸ê®ÆÀ˵ø ¹ï¸Ü¤è¶ô¤¤©Ò°õ¦æªº°Ê§@¦b¦¹¤]¯à°õ¦æ¡C¦b¦¹½d¨Ò¤¤¡A§A¥i¥H¨Ï¥Î¥ô¦ó¤@ºØ¤èªk³s½u¨ìNWind.mdb¸ê®Æ®w¡C


¡@

¹Ï8-13 «Ø¥ß¸ê®Æ³sµ²Àɮתº¤èªk

¦^¨ìADODCªº ÄÝ©Ê­¶ ¹ï¸Ü¤è¶ô¡A¤Á´«¨ì »{ÃÒ ¼ÐÅÒ­¶¡A¿é¤J¨Ï¥ÎªÌ¦WºÙ©M±K½X(¦pªG§Aªº¸ê®Æ®w»Ý­nªº¸Ü)¡A«ö¤@¤U ¸ê®Æ¿ý¨Ó·½ ¼ÐÅÒ­¶¡C¦b¦¹¼ÐÅÒ­¶§A¥i¥H©w¸q¥i¥H´£¨Ñ¸ê®Æµ¹Ã´µ²±±¨î¶µªº¸ê®Æ®w¸ê®Æªí¡B¹w¦sµ{§Ç¡B©ÎSQL¬d¸ß¡C¨Ò¦p¡A¦b¤W¤èªº²Õ¦X¤è¶ô¤¤¿ï¾Ü adCmdTex t¿ï¶µ¡A¦A¿é¤J¥H¤UªºSQL¬d¸ß¡G

Select * from Products

¦^¨ìªí³æ¨Ã·s¼W4­ÓTextBox±±¨î¶µ¡B4­ÓLable¡B©M1­ÓCheckBox±±¨î¶µ¡A¦p¹Ï8-14¡C±NCheckBox±±¨î¶µ©M©Ò¦³TextBox±±¨î¶µªºDataSourceÄÝ©Ê¥þ³¡³£³]©w¬°Adodc1¡A¨Ã±N¥¦­ÌªºDataFieldÄݩʳ]©w»P±±¨î¶µÃ´µ²ªº¸ê®Æ®w¤ºÄæ¦ì¦WºÙ¡C§A¤£¥²¥h²qÄæ¦ìªº¦WºÙ¡A¦]¬°¦b ÄÝ©Ê µøµ¡¤º´£¨Ñ¦³«D±`¤è«Kªº¤U©Ô²M³æ¡A²M³æ¤º¥]§t¤FPublishers¸ê®Æªí¤º©Ò¦³ªº¦WºÙ¡C´N¥»½d¨Ò¦Ó¨¥¡A¨Ï¥ÎProductName¡BUnitPrice¡BUnitsInStock¡BUnitsOnOrder©MDiscontinuedÄæ¦ì¡C

§A¤w·Ç³Æ°õ¦æ³o­Óµ{¦¡¡A¨Ã¨Ï¥ÎADO Data±±¨î¶µ4­Ó½bÀY«ö¶s¤Á´«¨C¤@µ§°O¿ý¡C¸ÕµÛ­×§ï¦h­ÓÄæ¦ì¡A²¾¨ì¤U¤@µ§°O¿ý¨Ã¦^ÀY¬Ý¬Ý·sªº­È¬O§_¤w¸g¤´¦b¡C¦p§A©Ò¨£¡A§A¤£¥Î¼gVisual Basicµ{¦¡½X¦¹¾÷¨î´N¯à§@¥Î¡C

§A¤£¥Î¼g¥ô¦ó¤@¦æµ{¦¡½X´N¥i¥H·s¼W°O¿ý¡C¦^¨ì³]­p¶¥¬q¡A±NADO Data±±¨î¶µªºEOFActionÄݩʳ]©w¬° 2-adDoAddNew ¡C±µµÛ¦A¦¸¦^¨ì½d¨Òµ{¦¡¤¤¡A«ö¤@¤U³Ì¥kÃ䪺½bÀY¶s¥H²¾¨ì³Ì«á¤@µ§°O¿ý¡A«ö¤@¤U¥kÃä¼Æ¨Ó²Ä¤G­Ó½bÀY¶s¥H²¾¨ì¤U¤@µ§°O¿ý¡C©Ò¦³ªºÃ´µ²±±¨î¶µ·|³Q²M°£¡A§A¥i¥H¿é¤J·s°O¿ýªºÄæ¦ì­È¡C°O¦í§A»Ý­n²¾¨ì¥t¤@µ§°O¿ýÅý§Aªº½s¿è¯à°÷³Qºû«ù¡C¦pªG§A¥u¬OÃö³¬ªí³æ¡A¥ô¦ó§A¦b²{¦³ªº°O¿ý©Ò°µ±oÅܧ󳣷|¿ò¥¢¡C


¡@

¹Ï8-14 ADO Data±±¨î¶µ½d¨ÒÀ³¥Îµ{¦¡¨Ï¥Î²Ä15³¹©Ò´y±ÔªºDataCombo±±¨î¶µ

¨Ï¥Îôµ²±±¨î¶µ
¡@

¤j³¡¥÷Visual Basic 6¤º«Øªº±±¨î¶µ¤ä´©¸ê®Æôµ²¡A¥]¬ATextBox¡BLabel¡BCheckBox¡BListBox¡BComboBox¡APictureBox¡A©MOLE±±¨î¶µ¡C¤@¯ë¦Ó¨¥¡ATextBox±±¨î¶µ¬O¥i½s¿èªº¦r¦ê©Î¼Æ­ÈÄæ¦ì¡ALabels±±¨î¶µ¬OµLªk½s¿èªºÄæ¦ì¡ACheckBoxes±±¨î¶µ¬OBoolean­È¡AListBoxes©MComboBoxes±±¨î¶µ«h¬O¦C¥X¦³®Ä­È¡C¦bVisual Basic 6®M¥ó¤¤¡A§A·|µo²{¤@¨Ç¤ä´©¸ê®Æôµ²ªº¥~³¡ActiveX±±¨î¶µ¡A¦pImageCombo¡BMonthView¡BDateTimePicker¡BMaskEdBox¡BRichTextBox¡BDataGrid¡BDataList¡BDataCombo©MHierarchical FlexGrid±±¨î¶µ¡C¦b¥»¬q¤¤¡A§Ú¤w¸g´£¨Ñ¤F¤@¨ÇÅý¤º«Øªº±±¨î¶µ¦¨¬°Ã´µ²±±¨î¶µ¤£¿ùªº«Øij©M¯¦³Z¡F¸ê®Æ·Pª¾ªºActiveX±±¨î¶µ±N¦b ²Ä10 ¡B 11 ¡B 12 ©M 15 ³¹¤¶²Ð¡C


»¡©ú

Visual Basic 6¦³¤@¨Ç¸ê®Æ·Pª¾ªº±±¨î¶µ-¤]´N¬ODBGrid¡B DBList¡BDBCombo¡B©MMSFlexGrid±±¨î¶µ-¬OµLªk»PADO Data±±¨î¶µ¬Û®eªº¡A¦Ó¥B¥u¯à»P¸ûªºData©MRemoteData±±¨î¶µ¤@°_¨Ï¥Î¡C©Ò¦³¤º«Øªº±±¨î¶µ³£¯àªºData±±¨î¶µ©M·sªºADO Data±±¨î¶µ¤@°_¨Ï¥Î¡C


©Ò¦³Ã´µ²±±¨î¶µªºDataChangedÄݩʦb°õ¦æ¶¥¬q¤¤¥u¦³BooleanÄÝ©Ê¡C·í¨Ï¥ÎªÌ(©Îµ{¦¡½X)­×§ï¤F±±¨î¶µ¤ºªº­È¡AVisual Basic«K±N¦¹Äݩʳ]©w¬°True¡CADOôµ²¾÷¨î¨Ï¥Î¦¹¼Ð¼m¨ÓÀˬd¥Ø«eªº°O¿ý¬O§_¤w¸g³Q½s¿è¡A¨Ã¦bÅã¥Ü·sªº°O¿ý«á±NÄÝ©Ê­«·s³]©w¬°False¡C³oªí¥Ü§A¥i¥HÁקKADO Data±±¨î¶µ¸g¥Ñ±N±±¨î¶µªºDataChangedÄݩʳ]©w¬°False¡A¦Ó±N±±¨î¶µªº­È·h²¾¨ì¸ê®Æ®wªºÄæ¦ì¡C


¤p¯µ³Z

DataChangedÄÝ©Ê»PADOôµ²¾÷¨î©¼¦¹¿W¥ß¡A¥B¦¹ÄÝ©Ê¥ÑVisual BasicºÞ²z¡Ð§Y¨Ï¦¹±±¨î¶µ¥Ø«e©|¥¼»P¸ê®Æ®wÄæ¦ìôµ²¡C¨Ò¦p¡A·í§A­n§PÂ_±±¨î¶µªº¤º®e¦b¸ü¤J¼Æ­È«á¬O§_¤w¸g³Q­×§ï®É¡A§A«K¥i¥H§Q¥Î¦¹ÄÝ©Ê¡C¦pªG§A¨S¦³¨Ï¥Î¦¹ÄÝ©Ê¡A§A«h»Ý­n¨Ï¥Îªí³æ¼h¯ÅªºBooleanÅܼơA¨Ã¥H¤â°Êªº¤è¦¡¦b±±¨î¶µªºChange©ÎClick¨Æ¥óµ{§Ç¤¤±N¥¦³]©w¬°True¡C


·í§A¨Ï¥Î¸ê®Æôµ²ªºLabel±±¨î¶µ®É¡A§AÀ³¸Ó±N¥¦ªºUseMnemonicsÄݩʳ]©w¬°False¡C¦pªG¥¦³Q³]©w¬°True (¹w³])­È¡A©Ò¦³¸ê®Æ®wÄæ¦ì¤ºªº¡¯¸¹³£·|³Q¿ù»~¸ÑĶ¬°§Ö³tÁä¦r¤¸ªº°t¸m°Ï¡CCheckBox±±¨î¶µ·|±N¹s­Èµø¬°vbUnchecked¡A¥ô¦ó«D¹sªº­Èµø¬°vbChecked¡A±NNull­Èµø¬°vbGrayed¡C¦ý·í§A­×§ï¦¹Äæ¦ì¤ºªº­È®É¡ACheckBox±±¨î¶µ¥Ã»··|±N0©M-1­ÈÀx¦s©ó¸ê®Æ®w¤º¡C¦³°ò©ó¦¹¡ACheckBox±±¨î¶µÀ³¸Ó¥u»PBooleanÄæ¦ìôµ²¡C


ª`·N

§AµLªk±NPictureBox±±¨î¶µ»P¦s©ñ¦bOLE±±¨î¶µÃþ«¬ªºAccess¸ê®Æ®wÄæ¦ì¤ºªº¹Ï¤ùôµ²¡A§A¥²¶·¨Ï¥ÎOLE±±¨î¶µ¡Côµ²ªºPictureBox±±¨î¶µ¥i¥HÅã¥Ü¦s©ñ¦b¹Ï¹³Ãþ«¬ªºSQL ServerÄæ¦ì¤ºªº¹Ï¤ùôµ²¡C


OptionButton±±¨î¶µ¨Ã«D¸ê®Æ·Pª¾ªº¡A¦]¦¹§A»Ý­n¥H¤Uªº¤èªk±N¥¦»PADO Data±±¨î¶µÃ´µ²¡C«Ø¥ß¤@­ÓOptionButton±±¨î¶µ°}¦C©M¤@­ÓÁôÂêºTextBox±±¨î¶µ¡A¨Ã±NÁôÂêºTextBox±±¨î¶µ»P¥Ø«e©Ò´£¨ìÊú¸ê®Æ®wÄæ¦ìôµ²¡C±µµÛ¦bªí³æ¼Ò²Õ¤¤¼g¤J¥H¤Uªºµ{¦¡½X¡G

Private Sub optRadioButton_Click(Index As Integer)

     'Change hidden TextBox's contents when user clicks on radio buttons.
    txtHidden.Text = Trim$(Index)
End Sub
Private Sub txtHidden_Change()
     'Select the correct radio button when the ADO Data control
     'assigns a new value to the hidden TextBox.
    On Error Resume Next
    optRadioButton(CInt(txtHidden.Text)).Value = True
End Sub

³Ì²z·Qªº¤èªk¬O¾Ö¦³¤@­ÓActiveX±±¨î¶µ¡A¦¹±±¨î¶µÅã¥ÜOptionButton±±¨î¶µ°}¦C¡A¨Ã±N³o¨Ç±±¨î¶µ»P¤@­Ó¸ê®Æ®wÄæ¦ìôµ²¡F¨Æ¹ê¤W¤@¨Ç°Ó¥Î±±¨î¶µ«K¦p¦¹°µ¡C¦ý²{¦bVisual Basic¤ä´©ActiveX±±¨î¶µªº«Ø¥ß¡A§A¦Û¤v«K¥i¥H¦b´X¤ÀÄÁ¤º«Ø¥ß³o¤@Ãþªº±±¨î¶µ¡C½Ð°Ñ¾\ ²Ä17³¹ ¥H¤F¸Ñ«Ø¥ßôµ²ActiveX±±¨î¶µªº¤èªk¡C

·í§A¨Ï¥ÎStyleÄݩʳ]©w¬°[2-DropdownList]ªºComboBox±±¨î¶µ¨Ã±NListBox±±¨î¶µ°µ¬°Ã´µ²±±¨î¶µ®É½Ð¯d·N¡C¦pªG¸ê®Æ®w¤ºªº­È»P²M³æ¤º¨ä¤¤¤@­Ó­È¤£²Å¦X®É¡A§A·|±o¨ì°õ¦æ¶¥¬qªº¿ù»~¡C

Visual Basic 6Åý§A¦b°õ¦æ¶¥¬q«ü¬£±±¨î¶µªºDataSourceÄÝ©Ê¡A¦]¦¹§A¥i¥H¦b°õ¦æ´Á¶¡Ã´µ²(©Î¨ú®øôµ²)¡G

'Bind a control at run time.
txtFirstName.DataField ="FirstName"
Set txtFirstName.DataSource = Adodc1
...
 'Unbind it.
Set txtFirstName.DataSource = Nothing

DataSourceÄݩʪº°ÊºA«ü©w¨Ã¤£¥Î©óªºData©MRemoteData±±¨î¶µ¡C

ADO Data±±¨î¶µ
¡@

ADO Data±±¨î¶µ¦³³\¦hADO Connection©MRecordsetª«¥óªº¥\¯à¡A³o¤@³¡¥÷·|¦b ²Ä13³¹ »¡©ú¡C¦b¥»¬q¤¤§Ú¥u¤¶²Ð¤@¨Ç§A¨Ï¥Î¦¹±±¨î¶µ«Ø¥ß¤@­Ó¤p«¬À³¥Îµ{¦¡®É»Ý­n³]©wªºÄÝ©Ê¡C

ConnectionStringÄݩʬO¦r¦ê¡A¥¦¥]§t«Ø¥ß³s½u®É»Ý­nªº©Ò¦³¸ê°T¡A´N¦p¦P§Ú¦b¤W¤@¬q©Ò»¡©ú¡C§A¥i¥H¨Ï¥ÎUserName©MPasswordÄݩʳ]©wµn¤J¸ê®Æ¡AConnectionTimeoutÄݩʨөw¸q³s½uªº¹O®É­È¡AModeÄÝ©Ê¥i¥H§PÂ_­þ¤@¶µ§@·~¦b³s½u¤W³Q¤¹³\¤F¡C¦³Ãö³o¨ÇÄݩʧó¸Ô²Óªº¸ê°T½Ð°Ñ¾\ ²Ä13³¹ ¡qConnection Object¡r¡C

ADO Data±±¨î¶µ¤j³¡¥÷ªºÄݩʬO¦VADO Recordsetª«¥ó­É¥Îªº¡CRecordSource¬O¸ê®Æªí¡B¹w¦sªºµ{§Ç¡B©Î¬O¶Ç¦^¸ê®Æ®w°O¿ýªºSQL©R¥O(¥¦»PRecordsetª«¥óªºSourceÄݩʹïÀ³)¡CCommandType¬O¦s©ñ¦bRecord-SourceÄݩʤºªº¬d¸ßÃþ«¬¡ACommandTimeout¬O©R¥O°õ¦æªº¹O®É­È(¥H¬í¬°³æ¦ì)¡ACursorLocation«ü©w´å¼Ð¬O§_À³¸Ó¦ì©ó¥Î¤áºÝ©Î¦øªA¾¹¤u§@¯¸¤W¡ACursorType¨M©w´å¼ÐªºÃþ«¬¡CCacheSize¬O¦b¨C¤@¦¸¸ê®ÆÂಾ¬O¥Ñ¸ê®Æ®wŪ¨úªº°O¿ý¼Æ¡ALockType«h·|¼vÅT¥Î¤áºÝÀ³¥Îµ{¦¡§ó·s¸ê®Æ®w¤º¸ê®Æªº¤è¦¡¡C§Ú±N¦b ²Ä13³¹ ©M ²Ä14³¹ ¤º¸Ô²Ó»¡©ú³o¨ÇÄÝ©Ê¡A»P´å¼Ð©MÂê©w¿ï¶µ¡C

ADO Data±±¨î¶µ¤]¦³¨â­ÓÄݩʬO¤£»PRecordsetª«¥ó¤ºªº¶µ¥Ø¹ïÀ³¡CEOFActionÄݩʯà¨M©w·í¨Ï¥ÎªÌ¥ø¹Ï·h²¾³Ì«á¤@µ§°O¿ý®É·|µo¥Íªº°Ê§@¡G0-adDoMoveLastªí¥Ü°O¿ý«ü¼Ð¤´°±¯d¦bRecordsetªº³Ì«á¤@µ§°O¿ý¡A1-adStayEOF³]©wEOF (End-Of-File)±ø¥ó¡A2-adDoAddNew·|¦Û°Ê¥[¤J¤@µ§·s°O¿ý¡CBOFActionÄÝ©Ê·|¨M©w·í¨Ï¥ÎªÌ¦b²Ä¤@µ§°O¿ý¬O¥Ø«e°O¿ý®É«ö¤@¤U³Ì¥ªÃ䪺½bÀY®É·|µo¥Íªº°Ê§@¡G0-adDoMoveFirst·|±N«ü¼Ð¯d¦b²Ä¤@µ§°O¿ý¡A1-adStayBOF³]©wBOF (Begin-Of-File)±ø¥ó¡C

¦b°õ¦æ¶¥¬q¤¤¡AADO Data±±¨î¶µÁÙ¦³¤@­ÓRecordsetÄÝ©Ê¡A¦¹ÄÝ©Ê·|¶Ç¦^­I´ºRecordsetª«¥óªº°Ñ·Ó¡C¦¹°Ñ·Ó¹ï©ó§Q¥Î±±¨î¶µ©Ò¦³ªº¥\¯à¦Ó¨¥¬O¥²¶·ªº¡A¦]¬°¥¦·|Åý§A¬°¨ä¥Lªº§@·~¥[¤J¤ä´©¡C¨Ò¦p¡A§A¥i¥H«Ø¥ß¨â­ÓCommandButton±±¨î¶µ¡A±N¥¦­ÌªºCaptionÄݩʳ]©w¬°AddNew©MDelete¡A¨Ã¦b¥¦­ÌªºClick¨Æ¥ó¤¤¼g¤J¥H¤Uªºµ{¦¡½X¡G

Private Sub cmdAddNew_Click()
    Adodc1.Recordset.AddNew
End Sub
Private Sub cmdDelete_Click()
    Adodc1.Recordset.Delete
End Sub

½Ð°O¦í¤§«eªº§@·~¨Ã«D¤@ª½³£³Q¤¹³\¡C¨Ò¦p¡A¦pªGADO Data±±¨î¶µ¦b°ßŪ¼Ò¦¡¤¤¤w¸g¶}±Ò¤F¸ê®Æ¨Ó·½¡A«h§AµLªk·s¼W·sªº°O¿ý©Î§R°£²{¦³ªº°O¿ý¡C§Y¨Ï¸ê®Æ¨Ó·½¤w¸g¦b°ßŪ¼Ò¦¡¤¤³Q¶}±Ò¤F¡A°O¿ý¤W¯S©wªº§@·~¥i¯à·|µL®Ä¡C¨Ò¦p¡A·íOrders¸ê®Æªí¤º¦³°O¿ý°Ñ·ÓCustomers¸ê®Æªí®É¡A§A«KµLªk§R°£Customers¸ê®Æªíªº°O¿ý¡C

Recordsetª«¥ó¦³¤@¨ÇÄÝ©Ê©M¤èªk¡A§A¥i¥H¥ÑADO Data±±¨î¶µ¨Ï¥Î¥¦­Ì¡C¨Ò¦p§A¥i¥H±Æ§Ç©Î¿z¿ïÅã¥Üªº°O¿ý¡A©Î¬O³]©w®ÑÅÒ¥H§Ö³tªº¦^¨ì«ü©wªº°O¿ý¡CADO Data±±¨î¶µ¨Ã¤£ª½±µ¾Ö¦³­I´ºªºConnectionª«¥ó¡A¦ý¥i¥H¨Ï¥Î­I´ºªºRecordsetª«¥óªºActiveConnectionÄÝ©Ê¡C¨Ò¦p¡A§A¥i¥H¨Ï¥Î¥H¤Uªºµ{¦¡½X¹ê¦æ¥æ©ö¡G

Private Sub Form_Load()
     'Start a transaction when the form loads.
    Adodc1.Recordset.ActiveConnection.BeginTrans
End Sub
Private Sub Form_Unload(Cancel As Integer)
     'Commit or roll back when the form unloads.
    If MsgBox(ioDo you confirm changes to records?lD¡AvbYesNo) = vbYes Then
        Adodc1.Recordset.ActiveConnection.CommitTrans
    Else
        Adodc1.Recordset.ActiveConnection.RollbackTrans
    End If
End Sub

¦pªG§A¨Ï¥Î¤§«eªºForm_Unload±`¦¡´_­ì¥æ©ö¡A§A»Ý­n¥s¥Î±±¨î¶µªºRefresh¤èªk¥HÀ˵ø°O¿ý¤º¤W¤@­Ó­È¡C


»¡©ú

¥æ©ö¬O¤@²Õ¬ÛÃöªº¸ê®Æ®w§@·~¡A³o¨Ç§@·~¦bÅÞ¿è¤Wµø¬°³æ¤@­Ó©R¥O¡A¾ã­Ó§@·~¤@°_¦¨¥\©Î¬O¥¢±Ñ¡C¨Ò¦p¡A·í§A±N¿ú¥Ñ¤@­Ó»È¦æ±b¤á·h²¾¨ì¥t¤@­Ó±b¤á®É¡A§AÀ³¸Ó±N¨â­Ó§@·~¥]§t¦b¤@­Ó¥æ©ö¤¤¡A¦p¦¹¤@¨Ó¦pªG²Ä¤G­Ó§@·~¥¢±Ñ¤F¡A«h²Ä¤@­Ó§@·~¤]·|¨ú®ø¡C·í§A½T©w¥æ©ö«á¡A§AÀ³¸Ó¥æ¥I³o¶µ¥æ©ö¡C·í§A­n¨ú®ø©Ò¦³©R¥Oªº®ÄªG®É¡A§AÀ³¸Ó±N¥¦´_­ì¡C


ADO Data±±¨î¶µ¤]¦³¼Æ­Ó¨Æ¥ó¬O¦VRecordset­É¥Îªº¡A³o¨Ç¨Æ¥ó§Ú¯d¨ì²Ä13³¹¦A±Ô­z¡A¦b¦¹§Ú¥u»¡©ú3­Ó¨Æ¥ó¡GMoveComplete¨Æ¥ó¦b·s°O¿ý¦¨¬°¥Ø«e°O¿ý®É·|¤Þµo¡A§A¥i¥H§Q¥Î¦¹¨Æ¥ó¨ÓÅã¥ÜµLªk¥Ñ¤@­Ó²³æôµ²±±¨î¶µÂ^¨úªº¸ê°T¡C¨Ò¦p¡A°²³]¸ê®Æ®w¤º¦³¤@­Ó¦W¬°PictureFileªºÄæ¦ì¥]§t¤@­ÓBMPÀɪº¸ô®|¡A§AµLªkª½±µ¨Ï¥Îôµ²±±¨î¶µÅã¥Ü¦¹ÂI°}¹Ï¡A¦ý§A¥i¥H³]©wMoveComplete¨Æ¥ó¨Ã¤â°Ê±N¦¹¹Ï¤ù¸ü¤JPictureBox±±¨î¶µ¡G

Private Sub Adodc1_MoveComplete(ByVal adReason As ADODB.EventReasonEnum¡A_
    ByVal pError As ADODB.Error¡AadStatus As ADODB.EventStatusEnum¡A_
    ByVal pRecordset As ADODB.Recordset)
    picPhoto.Picture = LoadPicture(Adodc1.Recordset("PictureFile"))
End Sub

WillChangeRecord¦bADO Data±±¨î¶µ±N¸ê®Æ¼g¤J¸ê®Æ®w¤§«e¥ß§Y¤Þµo¡C³o¬O³Ì¦nªº¦ì¸m¥i¥HÅçÃÒôµ²±±¨î¶µ¤º®e¨Ãµø»Ý­n¨ú®ø§@·~¡G

Dim ValidationError As Boolean           ? A form-level variable
Private Sub Adodc1_WillChangeRecord(ByVal adReason As _
    ADODB.EventReasonEnum¡AByVal cRecords As Long¡AadStatus As _
    ADODB.EventStatusEnum¡AByVal pRecordset As ADODB.Recordset)
    ? Check that fields are valid¡Acancel the update if not.
    If txtProductName = i iP Or Not IsNumeric(txtUnitPrice) Then
        MsgBox isPlease enter valid field valuesle¡AvbExclamation
        ValidationError = True
        adStatus = adStatusCancel
    End If
End Sub

Error¨Æ¥ó¬O°ß¤@¤£±qRecordsetª«¥óÄ~©Óªº¨Æ¥ó¡C·í¤@­Ó¿ù»~¬Oµo¥Í¦b¨S¦³Visual Basicµ{¦¡½X¥i¥H°õ¦æ®É¡AADO Data±±¨î¶µ«K·|¤Þµo¦¹¨Æ¥ó¡C³q±`³oºØ±¡ªp·|µo¥Í¦b¨Ï¥ÎªÌ«ö¤U¦¹±±¨î¶µ¥ô¦ó¤@­Ó½bÀY«ö¶s®É¨Ã¾É­P§@·~¥¢±Ñ(¨Ò¦p¡A·í§A¹Á¸Õ§ó·s¥Ñ¥t¤@¦ì¨Ï¥ÎªÌÂê©wªº°O¿ý®É)¡C·í§A¨ú®øWillChangeRecord¨Æ¥óªº§@·~®É¤]·|¤Þµo¦¹¨Æ¥ó¡C¨Ì·Ó¹w³]¡AADO Data±±¨î¶µ·|Åã¥Ü¼Ð·Çªº¿ù»~°T®§¡A¦ý¥u­n±NfCancelDisplay°Ñ¼Æ³]©w¬°True«K¥i¥H­×§ï¦¹¼Ð·Ç¦æ¬°¡C¥H¤Uªºµ{¦¡½X¥i§¹¦¨¤W¤@­Ó°õ¦æÄæ¦ìÅçÃÒªº½d¨Ò¡G

Private Sub Adodc1_Error(ByVal ErrorNumber As Long¡ADescription As String¡A_
    ByVal Scode As Long¡AByVal Source As String¡AByVal HelpFile As String¡A_
    ByVal HelpContext As Long¡AfCancelDisplay As Boolean)
     'Don't show validation errors (already processed elsewhere).
    If ValidationError Then
        fCancelDisplay = True
        ValidationError = False
    End If
End Sub

®æ¦¡¤Æ¸ê®Æ
¡@

­ì©lªºData©MRemoteData±±¨î¶µ¦³¤@­Ó«Ü¤jªº­­¨î¡A¨º´N¬OµLªk³]©w¸ê®Æ¦b¿Ã¹õ¤WÅã¥Üªº®æ¦¡¡C¨Ò¦p¡A¦pªG§A­nÅã¥Ü¤@¨Ç¤d¦ì¼Æ¤À¹j²Å¸¹¡A§A¥²¶·¼¶¼gµ{¦¡½X¡C§A¤]¥²¶·¼¶¼gµ{¦¡½X¤~¯à¥HÅã¥Ü§¹¾ã¤é´Á®æ¦¡(¨Ò¦p "October 17,1999")©Î¬O¤@¨Ç¼Ð·Ç®æ¦¡¨ÓÅã¥Ü¤é´Á¡C©Ò¥H¦pªG§Y¨Ï³o¤@ºØ°ò¥»ªº§@·~³£¥²¶·¼¶¼gµ{¦¡¶Ü¡A¨º»ò¨Ï¥Îôµ²±±¨î¶µ´N¨S¦³·N¸q¤F¡A¤£¬O¶Ü¡H

DataFormatÄÝ©Ê
¡@

ADOôµ²¾÷¨î¯à°÷¬°©Ò¦³ªºÃ´µ²±±¨î¶µ¥[¤J·sªºDataFormatÄÝ©Ê¡A¦Ó¦³®Äªº¸Ñ¨M¤W­zªº°ÝÃD¡C¦pªG§A«ö¤@¤U ÄÝ©Ê µøµ¡¤¤ªºData-Format¶µ¥Ø¡A«h·|Åã¥Ü¦p¹Ï8-15ªºÄÝ©Ê­¶¡C¦b¦¹§A¯à°÷¿ï¾Ü³\¦h°ò¥»ªº®æ¦¡Ãþ«¬(¦p¼Æ¦r¡B³f¹ô¡B©M®É¶¡)¡A¨C¤@­Ó³£¦³³\¦h®æ¦¡¿ï¶µ(¤p¼Æ¦ì¼Æ¡B¤d¦ì¼Æ¤À¹j²Å¸¹¡B³f¹ô²Å¸¹¡B¤é´Á/®É¶¡®æ¦¡¡Bµ¥µ¥)¡C

§A¤]¥i¥H³]©w¦Û­qªº®æ¦¡¡A¨Ï¥Î»PFormat¨ç¼Æ¬Û¦Pªº»yªk«ü©w®æ¦¡¦r¦ê(½Ð°Ñ¾\ ²Ä5³¹ )¡C¦ýADO Data±±¨î¶µµLªk±N¨Ï¥Î½ÆÂø®æ¦¡¦r¦ê®æ¦¡¤Æªº­È¥[¥H¸Ñ°£®æ¦¡¡A¦]¦¹¦b¸ê®Æ®w¤¤¥i¯à·|Àx¦s¨ì¿ù»~ªº¸ê®Æ¡C¨Ï¥ÎStdDataFormatª«¥ó«K¥i¥H©¿²¤¤W­zªº°ÝÃD¡A³o¤@³¡¥÷§Ú·|¦b¤U¤@¬q¸ÑÄÀ¡C

¦³¤@¨Ç±±¨î¶µªºDataFormatÄÝ©Ê¥i¯à¥¿½T¹B§@¡C¨Ò¦p¡A¨Ï¥ÎDataCombo±±¨î¶µªºDataFormatÄݩʨ䣷|¼vÅT¦¹¶µ¥Ø¦b²M³æ³¡¥÷ªº®æ¦¡¡CDataGrid±±¨î¶µ¦³DataFormats¶°¦X¡A¦b¶°¦X¤¤¨C¤@­Ó¶µ¥Ø³£·|¼vÅT®æ½uÄæ¦ìªº®æ¦¡¡C


¡@

¹Ï8-15 DataFormatÄÝ©Ê­¶

4

StdDataFormatª«¥ó
¡@

¬°¤F¯à°÷¨Ï¥ÎStdDataFormatª«¥ó¡A§A¥²¶··s¼WMicrosoft Data Formatting Object Libraryªº°Ñ·Ó¡A§A¥²¶·±N¹ïÀ³ªºMSSTDFMT.DLLÀÉ®×µo§G¨ì©Ò¦³ªºÀ³¥Îµ{¦¡¤W¡C

³o¨Çª«¥óªº²Ä¤@­Ó¥Îªk¬O¦b°õ¦æ¶¥¬q³]©wôµ²Äæ¦ìªºDataFormatÄÝ©Ê¡C¨Ò¦p¡A·í§A¦b°õ¦æ´Á¶¡¨Ï¥Î±±¨î¶µ¯x°}(½Ð°Ñ¾\ ²Ä3³¹ )«Ø¥ß±±¨î¶µ©Î¬O¨Ï¥Î·sªºVisual Basic 6°ÊºA±±¨î¶µ«Ø¥ß¥\¯à(½Ð°Ñ ²Ä9³¹ )®É¡A§A¥²¶·³o¼Ë°µ¡C­Y­n­×§ïôµ²±±¨î¶µ¤º¸ê®Æ³Q®æ¦¡ªº¤è¦¡¡A§A¥i¥H«Ø¥ß¤@­Ó·sªºStdDataFormatª«¥ó¡A³]©wÄÝ©Ê¡A¦A³]©w±±¨î¶µªºDataFormatÄÝ©Ê¡Aµ{¦¡½X¦p¤U¡G

Private Sub Form_Load()
     'Create a new formatting object and assign it to a bound field.
    Dim sdf As New StdDataFormat
    sdf.Type = fmtCustom
    sdf.Format = "mmm dd¡Ayyyyl"¡M
    Set txtShippedDate.DataFormat = sdf
     'Force the Data control to correctly display the first record.
    Adodc1.Recordset.Move 0
End Sub

StdDataFormatª«¥ó³Ì­«­nªºÄݩʬOType¡A¦¹Äݩʦ³¥H¤Uªº­È¡G0-fmtGeneral¡B1-fmtCustom¡B2-fmtPicture¡B3- fmtObject¡B4-fmtCheckbox¡B5-fmtBoolean©Î6-fmtBytes¡C¦pªG§A¨Ï¥Î¦Û­qªº®æ¦¡¿ï¶µ¡A§A¥i¥H±NFormatÄݩʳ]©w¬°®æ¦¡¦r¦ê¡A¥¦ªº»yªk»PVBA Format¨ç¼Æ²Ä2­Ó°Ñ¼Æªº»yªk¬Û¦P¡C

·í¥ÑBooleanÄæ¦ìÂ^¨ú¸ê®Æ«á¡A§A³q±`·|¨Ï¥ÎCheckBox±±¨î¶µ©MfrmCheckbox³]©w¡C¦ý§A¥i¥H¨Ï¥ÎLabel©ÎTextBox±±¨î¶µ¸ÑĶBooleanÄæ¦ìªº¤º®e¨ÃÅã¥Ü¦³·N¸qªº±Ô­z¡C¦b¦¹±¡ªp¤U¡A§A¥²¶·±N¦r¦ê³]©w¬°FalseValue¡BTrueValue©M(¿ï¾Ü©Ê) NullValueÄÝ©Ê¡G

Private Sub Form_Load()
    Dim sdf As New StdDataFormat

    sdf.Type = frmBoolean
     'Set meaningful strings for False¡ATrue¡Aand Null values.
    sdf.FalseValue = i In Productionla
    sdf.TrueValue = i.Discontinuedla
    sdf.NullValue = i.(unknown)ll
    Set lblDiscontinued.DataFormat = sdf
     'Force the Data control to correctly display the first record.
    Adodc1.Recordset.Move 0
End Sub

¦]¦¹¡A§AÀ³¸Ó¥u¦bLabel¡BÂê©wªºTextBox¡B©MListBox±±¨î¶µ¤W¨Ï¥Î¦¹§Þ³N¡A¦]¬°¨Ï¥ÎªÌ¤£¯à°÷¿é¤J¤U¦C¤T­ÓÄÝ©Ê¥H¥~ªº¦r¦ê¡GFalseValue¡BTrueValue¡BNullValueÄÝ©Ê¡C

StdDataFormatª«¥ó¯u¥¿ªº¤O¶q¬O¦¹ª«¥ó´£¤É¨Æ¥óªº¯à¤O¡C§A¥i¥H±NStdDataFormatª«¥ó·Q¹³¬O¦ì¦b¸ê®Æ¨Ó·½©M¸ê®Æ®ø¶OªÌ¤§¶¡¡C¦b¦¹±¡ªp¤U¡A§A±NADO Data±±¨î¶µ°µ¬°¸ê®Æ¨Ó·½¡A±Nôµ²±±¨î¶µ°µ¬°¸ê®Æ®ø¶OªÌ¡AStdDataFormatª«¥ó¥i¥H¦b¥ô¦óADOôµ²¾÷¨î§@¥Îªº´Á¶¡¨Ï¥Î¡CStdDataFormatª«¥ó¥iÅý§A¥D°Ê¦a³]©w¸ê®Æ¥Ñ¸ê®Æ¨Ó·½·h²¾¨ì¸ê·½®ø¶OªÌªº®É¶¡©M¤Ï¦V·h²¾ªº®É¶¡¡F§A¥i¥H¨Ï¥ÎFormat©MUnformat¨Æ¥ó¨Ó§¹¦¨¡C

­Y­n³]©w³o¨Ç¨Æ¥ó¡A§A¥²¶·±NStdDataFormatª«¥ó«Å§i¬°ªí³æ¼h¯ÅªºÅܼơA¨Ï¥ÎWithEventsÃöÁä¦r¡CFormat¨Æ¥ó·|¤Þµo¦ó®É¥Ñ¸ê®Æ®wŪ¨ú¼Æ­È¤Î¦b±±¨î¶µ¤¤Åã¥Ü¦¹¼Æ­È¡C¦pªG¨Ï¥ÎªÌ­×§ï¤F³o­Ó¼Æ­È¡AUnformat¨Æ¥ó·|¤Þµo¦ó®ÉADO Data±±¨î¶µ±N¦¹¼Æ­ÈÀx¦s¦^¸ê®Æ®w¡C³o¨â­Ó¨Æ¥ó³£·|±µ¦¬DataValue°Ñ¼Æ¡A¦¹°Ñ¼Æ¦³¥H¤U¨â­ÓÄÝ©Ê¡GValue¬O³Q¶Ç°eªº¼Æ­È¡ATargetObject¬Oôµ²±±¨î¶µ-³q±`¬O¸ê®Æ®ø¶OªÌ¡C¤@¯ë¦Ó¨¥¡A¦pªG§A¤â°Ê®æ¦¡¤Æ©Î¥¼®æ¦¡¤Æ³o¨Ç¨Æ¥ó¤ºªº­È¡A§A«K¤£»Ý­n³]©wStdDataFormatª«¥ó¥ô¦ó¨ä¥LªºÄÝ©Ê¡C

¹Ï8-16¬°¤@­Ó²³æªºµ{¦¡(½Ð°Ñ¦Ò¥»®Ñ©ÒªþªºCD)¡A¦¹µ{¦¡·|Åã¥ÜNWind.mdb¸ê®Æ®wOrders¸ê®Æªíªº¸ê®Æ¡CFreight¼Æ­È¥i¥H¨Ï¥Î¬üª÷©Î¼Ú¤¸ªí¥Ü¡A¦ý¸ê®Æ¥u¥H¬üª÷®æ¦¡Àx¦s¸ê®Æ¡A¦]¦¹§A»Ý­n°õ¦æ´«ºâ¡Cµ{¦¡½X¦p¤U¡G

'How many euros in one dollar?
 '(Of course¡Ain a real program this would be a variable.)
Const DOLLARS_TO_EURO = 1.1734
Dim WithEvents sdfFreight As StdDataFormat
Private Sub Form_Load()
    Set sdfFreight = New StdDataFormat
    Set txtFreight.DataFormat = sdfFreight
     'Force the Data control to correctly display the first record.
    Adodc1.Recordset.Move 0
End Sub
Private Sub sdfFreight_Format(ByVal DataValue As StdFormat.StdDataValue)
     'Convert to euros if necessary.
    If optFreight(1) Then
        DataValue.Value = Round(DataValue.Value * DOLLARS_TO_EURO¡A2)
    End If
End Sub
Private Sub sdfFreight_UnFormat(ByVal DataValue As StdFormat.StdDataValue)
     'Convert back to dollars if necessary.
    If optFreight(1) Then
        DataValue.Value = Round(DataValue.Value / DOLLARS_TO_EURO¡A2)
    End If
End Sub
Private Sub optFreight_Click(Index As Integer)
    If Index = 0 Then
         'Convert from euros to dollars.
        txtFreight = Trim$(Round(CDbl(txtFreight) / DOLLARS_TO_EURO¡A2))
    Else
         'Convert from dollars to euros.
        txtFreight = Trim$(Round(CDbl(txtFreight) * DOLLARS_TO_EURO¡A2))
    End If
End Sub


¡@

¹Ï8-16 ¨Ï¥ÎStdDataFormaª«¥óÅýÅã¥Ü®æ¦¡»P¦s©ñ¦b¸ê®Æ®wªº­È©¼¦¹¿W¥ß

§A¥i¥H¨Ï¥ÎDataValue.TargetObjectÄݩʼvÅTôµ²±±¨î¶µªº¦æ¬°©Î¥~Æ[¡C¨Ò¦p¡A§A¥i¥HÅýFreight¼Æ­È¦b°ª©ó30¬üª÷®É¥H¬õ¦âÅã¥Ü¡G

Private Sub sdfFreight_Format(ByVal DataValue As StdFormat.StdDataValue)
     'Show the value in red ink if >30 dollars.
    If DataValue.Value > 30 Then
        DataValue.TargetObject.ForeColor = vbRed
    Else
        DataValue.TargetObject.ForeColor = vbBlack
    End If
     'Convert to euros if necessary.
    If optFreight(1) Then
        DataValue.Value = Round(DataValue.Value * DOLLARS_TO_EURO¡A2)
    End If
End Sub

StdDataFormatª«¥ó¦³¤@­Ó¦³½ìªº¥\¯à¬O§A¥i¥H¬°¦h­Ó±±¨î¶µªºDataFormatÄÝ©Ê«ü©w¬Û¦Pªº¨Ò¶µ¡C·í§A­nºÞ²zFormat©MUnformat¨Æ¥ó®É³o­Ó¥\¯à¯S§O¦³¥Î¡A©Ò¥H§A¥i¥H¥u¨Ï¥Î¤@­Ó¤Á¤JÂI«K¯à°÷®æ¦¡¿Ã¹õ¤W¦h­ÓÄæ¦ì¡C§A¥i¥H¨Ï¥ÎDataValue.TargetObject.NameÄݩʨӵo²{­þ¤@­Óôµ²±±¨î¶µ¥¿¦b­n¨D®æ¦¡¤Æ¡Aµ{¦¡½X¦p¤U¡G

Private Sub sdfGeneric_Format(ByVal DataValue As StdFormat.StdDataValue)
    Select Case DataValue.TargetObject.Name
        Case iatxtFreightle¡A"txtGrandTotal"
             'These are currency fields.
            DataValue.Value = FormatCurrency(DataValue.Value)
        Case "ProductName"
             'Display product names in uppercase characters.
            DataValue.Value = UCase$(DataValue.Value)
    End Select
End Sub

StdDataFormatª«¥óªº²Ä3­Ó¨Æ¥ó¡AChanged¡A¦¹¨Æ¥ó·|¦b¥ô¦ó¤@­Óª«¥óÄݩʤw¸gÅܧó®É¤Þµo¡C§A³q±`¥i¥H­«·s¾ã²zÄæ¦ìªº¤º®e¨Ó¤ÏÀ³¦¹¨Æ¥ó¡A¦p¤U¡G

Private Sub sdfGeneric_Changed()
     'This forces the ADO Data control to reread the current record.
    Adodc1.Recordset.Move 0
End Sub

¥H¤U¬OStdDataFormatª«¥ó¨ä¥L¬ÛÃöªº¸ê°T¡G

¸ê®Æªí³æºëÆF
¡@

¸ê®Æªí³æºëÆF¬OVisual Basic 6ªº¼W¯q¶°¡A¥¦·|¦Û°Ê«Ø¥ß¤@­Ó¦³¤@²Õ±±¨î¶µªºªí³æ¡A³o¨Ç±±¨î¶µ³£¤w¸g»P¸ê®Æ¨Ó·½Ã´µ²¡C¥¦¤]¥i¥H¤@¯ë¸ê®Æ®w§@·~(¨Ò¦p·s¼W©Î§R°£°O¿ý)ªº«ö¶s¡CVisual Basic 5¤]¦³¸ê®Æªí³æºëÆF¡A¦ý¥¦¤w¸g³Q­×§ï¯à¨Ï¥ÎADO Data±±¨î¶µ¡C¸ê®Æªí³æºëÆF¤]¯à°÷¤£¨Ï¥ÎADO Data±±¨î¶µ¡A¥u­n±NADO Recordset°µ¬°¸ê®Æ¨Ó·½§Y¥i¡A¥¦¬Æ¦Ü¥i¥H«Ø¥ß¤@­Ó¦³¯S®í¥\¥Îªº¸ê®Æ¨Ó·½Ãþ§O¼Ò²Õ¡C

¸ê®Æªí³æºëÆFªº¨Ï¥Î¬O«D±`ª½±µªº¡A¦]¦¹§Ú¤£·|¸Ô²Ó»¡©ú¨C¤@­Ó¨BÆJ¡C¹Ï8-17¬°¤¤¶¡ªº¨BÆJ¡A§A­n¨M©w§A­n«Ø¥ßªºªí³æÃþ«¬¤ÎÀ³¸Ó¨Ï¥ÎªºÃ´µ²Ãþ«¬¡C§A¥i¥H²£¥Í¤@²Õôµ²±±¨î¶µ¡B¤@­ÓDataGrid©ÎHierarchical FlexGrid±±¨î¶µ¡B¥D­n/²Ó¸`ªí³æ©ÎMSChart¡CºëÆF¦b«Ø¥ß³æ¤@µ§°O¿ý©M¥D­n/²Ó¸`ªí³æ®É¯S§Oªº¦³¥Î¡C¨Ò¦p¹Ï8-18¤¤ªºªí³æ¦b¤W¥b³¡Åã¥Ü­q³æ¡A¦b¤U¥b³¡®æ½u¤¤Åã¥Ü¨C¤@µ§°O¿ýªº¸ê°T¡C


¡@

¹Ï8-17 ¸ê®Æªí³æºëÆF«Ø¥ß5ºØ¤£¦PÃþ«¬ªºÃ´µ²ªí³æ

§A­n¿ï¾Ü¨Ï¥Î­þ¤@­Óªí³æ©Î¬OÀ˵ø°µ¬°°O¿ý¨Ó·½¡C§A¤]­n¿ï¾Ü¦bµ²ªGªí³æ¤¤À³¥]¬A­þ¤@¨ÇÄæ¦ì¤Î¿é¥X¬O§_­nÀx¦s«ü©wÄæ¦ì¤º¡C¦pªG§A­nôµ²¥D­n/²Ó¸`ªí³æ¡A§A¥²¶·¿ï¾Ü¨â­Ó¤£¦Pªº°O¿ý¨Ó·½¡A¤@­Ó¬O¥D­nªí³æªº¡A¤@­Ó¬O²Ó¸`ªí³æªº¡A¦Ó¥B§A¤]­n¥Ñ¨C¤@­Óªí³æ¤º¿ï¾Ü¤@­ÓÄæ¦ì¨Ó±N¨â­Ó¨Ó·½³sµ²¦b¤@°_¡C¦b Control Selection ¼ÐÅÒ­¶¤¤¡A§A¥i¥H¿ï¾Ü¦bªí³æ¤W­n©ñ¸m­þ¤@¨Ç«ö¶s¡A¦pAdd¡BUpdate¡BDelete¡BRefresh¡B©MClose¶s¡C³Ì«á¦bºëÆFªº³Ì«á¤@­Ó¨BÆJ¤¤¡A§A¥i¥H±N©Ò¦³ªº³]©wÀx¦s¦bRWP³]©wÀɤ¤¡A¦]¦¹§A«K¥i¥H¦b¤é«á¦^¨ì³o­ÓºëÆF¦Ó¤S¤£¥Î­«·s¿é¤J©Ò¦³ªº¿ï¶µ¡C


¡@

¹Ï8-18 ®Ú¾ÚNWind.mdb¸ê®Æ®wªºOrders©MOrder Details¸ê®Æªí©Ò§¹¦¨ªº¥D­n/²Ó¸`ªí³æ

¦pªG¥u¬O¬°¤F¬ü¤Æªº­ì¦]¡A§A«Ü¦³¥i¯à»Ý­n­×¥¿¥Ñ¸ê®Æªí³æºëÆF²£¥Íªºªí³æ©Îµ{¦¡½X¡C¦ý§A¥i¯à­n¾Ç²ß¦p¦ó¼¶¼g¤@­Ó²³æ°õ¦æªºADOµ{¦¡½X¡A¦AÂsÄý¥¦ªºµ²ªG¡C©ÎªÌ§A¥i¥H¥u¨Ï¥ÎºëÆF«Ø¥ß¸ê®Æ¨Ó·½Ãþ§O(¸ê®Æ¨Ó·½Ãþ§O±N¦b ²Ä18³¹ ¤¤»¡©ú)¡C

DATAENVIRONMENT³]­p¤u¨ã
¡@

DataEnvironment³]©w¤u¨ã¬OVisual Basic 6³Ì¦³½ìªº·s¥\¯à¤§¤@¡C²¨¥¤§¡A¥¦¬O§A¦b°õ¦æ¶¥¬q«Ø¥ßªºADOª«¥ó¦b³]­p¶¥¬qªº¥Nªí¡C¦¹¯à¤O¡u«D±`¡vªº¦³½ì¡A¦]¬°¥¦·|±N¬Û¦Pªºµ{¦¡Ãþ«¬»P¸ê®Æ®w¶}µoôµ²¡F³o¬OVisual Basic¦b¼Æ¦~«e©Òªº¾É¤J¡A¨ÃÅýWindowsªºµ{¦¡³]­pÅܱo«Ü²³æ©M§Ö³t¡C

·í§A¨Ï¥Îªí³æ³]­p¤u¨ã®É¡A§A¹ê»Ú¤W¬O¦b³]­p¶¥¬q¤¤©w¸qVisual Basic«Ø°õ¦æ¶¥¬q©Ò«Ø¥ßªºªí³æ©M±±¨î¶µ¡C§A¥i¥H¥Hµøıªº¤è¦¡°µ¨M©w¡A¦Ó¤£¥Î¾á¤ßVisual Basic¦bµ{¦¡°õ¦æ®É¹ê»Úªº§@·~¡C¦P¼Ëªº§A¥i¥H¨Ï¥ÎDataEnvironment³]­p¤u¨ã©w¸qADO Connections¡BCommands¡B©MRecordsetª«¥óªº¦æ¬°¡C§A¥i¥H¦b³]­p¶¥¬q¤¤«ö¤UF4Áä¥H¶}±ÒÄݩʵøµ¡¡A¨Ã³]©w¥¦­ÌªºÄÝ©Ê¡F©Î¬O¨Ï¥Î¦Û­qªºÄÝ©Ê­¶¡C

DataEnvironment³]­p¤u¨ã¬OUserConnection³]­p¤u¨ã(Visual Basicªº²Ä¤@­Ó¥~³¡³]­p¤u¨ã)ªº«á¥N¡CUserConnection³]­p¤u¨ã¥]§t¦bEnterprise Edition of Visual Basic 5¤¤¡A¨Ã±Æ°£¨Ï¥ÎRDO³s½u¡A¦]¦¹¥u¦³¤@³¡¥÷ªºVisual Basic¶}µoªÌ´¿¸g¨Ï¥Î¹L¥¦©Î¬Oª¾¹D¥¦ªº¦s¦b¡CDataEnvironment³]­p¤u¨ã¤ñ¥¦ªº«e½ú§ó¬°±j¤j¡C¥¦¯à¨Ï¥Î¥ô¦ó¤@ºØ¥»¾÷©Î»·ºÝADO³s½u¡A¬Æ¦Ü¤ä´©¦h­Ó³s½u¡C¦¹¥~¡A¥¦¥i¥Hµø¬°ADO¸ê®Æ¨Ó·½¡A¦]¦¹§A¥i¥H±NÄæ¦ì»P¥¦Ã´µ²¡A§Ú¦bµy«á±N·|»¡©ú¡C

¨Ï¥Î³]­p¶¥¬q©Ò©w¸qªºDataEnvironmentª«¥ó¦Ó¤£¨Ï¥Îµ{¦¡½X©Ò«Ø¥ßªºADOª«¥óªº¥t¤@­ÓÀuÂI«K¬OData-Environment¨Ò¶µ¬O¥i¥H¥]§t¨ä¥Lªºª«¥ó©Mµ{¦¡½X¨ÓºÞ²z¦¹ª«¥ó¡C§A¥i¥H±N¤½¥ÎÄÝ©Ê©M¤èªk·s¼W¦ÜDataEnvironment³]­p¤u¨ã¤¤¡A¦p¦¹«K¥i¥H¤j´T§ïµ½ª«¥óªº­«·s¨Ï¥Î©Ê¡A´N¦p¦P¥¦­Ì¬O±M¬°¸ê®Æ®w¨Ï¥ÎªºÃþ§O¼Ò²Õ¤@¯ë¡C§Ú¬Û«H¾A·íªº¨Ï¥ÎDataEnviromentª«¥ó·|­²·s¸ê®Æ®wÀ³¥Îµ{¦¡«Ø¥ßªº¤è¦¡¡C

­Y­n¦b¥Ø«eªº±M®×¤¤·s¼WDataEnvironment³]­p¤u¨ã¡A½Ð¿ï¾Ü ±M®× ¥\¯àªí¤ºªº ·s¼WData Environment ©R¥O¡C¦¹©R¥O¥u¦³¦b§A¤w¸g±N°Ñ·Ó·s¼W¨ìMicrosoft Data Environment Instance 1.0 library®É¤~·|Åã¥Ü¡C§A¤]¥i¥H¥Ñ ¸ê®ÆÀ˵ø µøµ¡¤¤«Ø¥ßDataEnvironment³]­p¤u¨ã¡C³Ì«á¡A§A¥i¥H¥Ñ±M®×®w¤¤«Ø¥ß·sªºData Project¡C¦b¦¹±¡ªp¤U¡AVisual Basic·|¬°§A«Ø¥ß©Ò¦³¥²¶·ªº°Ñ·Ó©MDataEnvironment³]­p¤u¨ã¨Ò¶µªº±M®×¡C

Connectionª«¥ó
¡@

DataEnviroment³]­p¤u¨ã¤¤¥D­nªºª«¥ó¬OConnectionª«¥ó¡C¥¦¼sªxªº¹ïÀ³¨ìForm³]­p¤u¨ãªºªí³æª«¥ó¡A¤]´N¬O³Ì¤W¼hªºª«¥ó¡C¦ý»Pªí³æ¤£¦Pªº¦a¤è¬O¡ADataEnvironment³]­p¤u¨ã¨Ò¶µ¥i¥H¥]§t¦h­ÓConnectionª«¥ó¡C

«Ø¥ßConnectionªº¤èªk¦³«Ü¦h¡C·í§A«Ø¥ßDataEnvironment®É¡A¥¦¤w¸g¥]§t¤F¹w³]ªºConnectionª«¥ó¡A©Ò¥H§A¥u»Ý­n«Ø¥ß¥¦ªºÄÝ©Ê¡C­Y­n³]©wÄÝ©Ê¡A§A¥i¥H«öF4Åã¥Ü¤@¯ëªº ÄÝ©Ê µøµ¡¡A©ÎªÌ(³Ì¦n¬O)¦bª«¥ó¤W«ö¤@¤U¥kÁä¨Ã¿ï¾Ü ÄÝ©Ê ¥HÅã¥Ü¥¦ªº¦Û­qÄÝ©Ê­¶(«ö¤@¤UDataEnviroment¤u¨ã¦C¤Wªº Äݩʵøµ¡ ¶s¤]¥i¥H±o¨ì¦P¼Ëªº®ÄªG)¡C§Ú¤£·|ªá¥ô¦ó¤@ÂI®É¶¡»¡©úConnectionª«¥óªºÄÝ©Ê­¶¡A¦]¬°§A¤w¸g¼ô±x³o¨ÇÄÝ©Ê­¶¤F¡C ´£¨ÑªÌ¡B³s½u¡B¶i¶¥¡B¥þ³¡ ¸ê®Æ­¶»P§A¦b ¸ê®ÆÀ˵ø µøµ¡¤¤³]©w¸ê®Æ³sµ²ªºÄݩʩάO¦b«Ø¥ßADO Data±±¨î¶µªºConnectionStringÄݩʮɩҬݨ쪺ÄÝ©Ê­¶¬Û¦P¡C

¤@¯ëªº[ÄÝ©Ê]µøµ¡¤º¦³¤@¨ÇÄݩʤ£¥X²{¦b¦Û­qÄÝ©Ê­¶¤¤¡CDesignUserName©MDesignPasswordÄÝ©Ê¥iÅý§A³]©w«Ø¥ßDataEnvironmentª«¥ó®É­n¨Ï¥Îªº¨Ï¥ÎªÌ¦WºÙ©M±K½X¡ARunUserName©MRunPasswordÄÝ©Ê¥iÅý§A³]©wµ{¦¡°õ¦æ®É¨Ï¥Îªº¨Ï¥ÎªÌ¦WºÙ©M±K½X¡C¨Ò¦p¡A§A¥i¯à­n¨Ï¥ÎAdministratorÃѧO­È¶}µoÀ³¥Îµ{¦¡¡A¦AÀˬd·íGuest¨Ï¥ÎªÌµn¤J®ÉÀ³¥Îµ{¦¡¦b°õ¦æ¶¥¬qªº¦æ¬°¤è¦¡¡C§A¥i¥H¨M©w·í¶}±Ò³s½u®É¬O§_­n¬Ý¨ì©R¥O´£¥Ü¦r¤¸¡A§A¤]¥i¥H¦b³]­p¶¥¬q©M°õ¦æ¶¥¬q¤¤¨Ï¥Î¤£¦Pªº³]©w¡CDesignPromptBehavior©MRunPromptBehaviorÄÝ©Ê¥i¥H³]©w¥H¤Uªº­È¡G1-adPromptAlways (¥Ã»·Åã¥Üµn¤J¹ï¸Ü¤è¶ô¡A¤¹³\¨Ï¥ÎªÌÅܧóµn¤J¸ê®Æ)¡A2-adPromptComplete (¥u¦³¦b¤@©Î¦h­Ó¥²¶·°Ñ¼Æ¿ò¥¢®É¤~·|Åã¥Üµn¤J¹ï¸Ü¤è¶ô)¡A3-adPromptCompleteRequired(¦p«e¤@­Ó­È¡A¦ý¥u¤¹³\¨Ï¥ÎªÌ¿é¤J¥²¶·°Ñ¼Æ)¡A©M4-adPromptNever(¥Ã»·¤£Åã¥Üµn¤J¹ï¸Ü¤è¶ô¡A¦pªG¦³¤@©Î­Ó°Ñ¼Æ¿ò¥¢¡A«h·|±N¿ù»~¦^¶Çµ¹À³¥Îµ{¦¡)¡C§A³q±`·|±NDesignPromptBehaviorÄݩʳ]©w¬°adPromptComplete¡A±NRunPromptBehaviorÄݩʳ]©w¬°adPromptNever¡F«áªÌ¥i¥HÁקK©~¤ß¤£¨}ªº¨Ï¥ÎªÌµn¤J¨ä¥Lªº¸ê®Æ¨Ó·½¨ÃÀH¾÷¿é¤J¨Ï¥ÎªÌ¦WºÙ©M±K½X¡Aª½¨ì¥L­Ì¥i¥HºÞ²z¨t²Î¡C³Ì«á¡ADesignSaveAuthentication©MRunSaveAuthenticationÄÝ©Ê·|§PÂ_¥ý«e©Ò´y­zªºµn¤J¸ê°T¬O§_¤À§OÀx¦s¨ìVBP©ÎEXEÀɤº¡C¦b¦¹´£¿ô§A¤@ÂI¡GEXEÀɤºªº¨Ï¥ÎªÌ¦WºÙ©M±K½X¨Ã¥¼¥[±K¡A©Ò¥HÀb«È¥i¯à·|±N¥¦¸ü¤J½s¿è¾¹¤¤©Î¬O¥H¨ä¥Lªº¤èªk­åªR¸ê®Æª½¨ì¥L­Ì±o¨ì©Ò­nªº¸ê®Æ¬°¤î¡C

Commandª«¥ó
¡@

DataEnvironment³]­p¤u¨ãªºCommandª«¥ó¥Nªí¦b¸ê®Æ®w¤W°õ¦æªº°Ê§@¡C©R¥Oª«¥ó¥Ã»·¬OConnectionª«¥óªº¤l¶µ¥Ø¡A´N¹³±±¨î¶µ¥Ã»·¬Oªí³æªº¤l¶µ¥Ø¤@¼Ë¡C§óºë½T¤@ÂI¨Ó»¡¡A§A¥i¥H«Ø¥ß¿W¥ßªºCommandª«¥ó¡A¦ýµLªk¨Ï¥Î¥¦¡A°£«D§AÅý¥¦¦¨¬°Connectionª«¥óªº¤l¶µ¥Ø¡C

«Ø¥ßCommandª«¥ó
¡@

«Ø¥ßCommandª«¥ó³Ì²³æªº¤èªk«K¬O¥Ñ ¸ê®ÆÀ˵ø µøµ¡¤¤±N¸ê®Æªí¡BÀ˵ø©Î¹w¦sªºµ{§Ç©ì¦²¨ì DataEnvironment µøµ¡¤¤¡C±µµÛVisual Basic¦A«Ø¥ß»P¸ê®Æ§¨¡BÀ˵ø©Î¹w¦sªºµ{§Ç¹ïÀ³ªºCommandª«¥ó¡A¦p¦³»Ý­nªº¸Ü¥¦¤]·|«Ø¥ß¤÷¶µConnectionª«¥ó¡CCommandª«¥ó¥u¯à¬O°Ñ·Ó¥¦©ÒÄݸê®Æ®wªºConnectionª«¥óªº¤l¶µ¥Ø¡C§A¤]¥i¥H«Ø¥ß¦h­Ó¹ïÀ³¨ìÀx¦s¦b¸ê®Æ®w¤¤µ{§ÇªºCommandª«¥ó¡A¥u­n«ö¤@¤UDataEnvironment¤u¨ã¦C¤WªºInsert Stored Procedures«ö¶s§Y¥i¡C§Ú¨Ï¥Î³o­Ó±¶®|§Ö³t«Ø¥ß¦p¹Ï8-19ªºCommandª«¥ó¡C

Commandª«¥ó¦³¨âºØ¡G¤@­Ó¶Ç¦^Recordsets¡A¥t¤@­Ó¨S¦³¡C«eªÌ¬OSQL¬d¸ß¡B¹w¦sµ{§Ç¡B©Î¶Ç¦^RecordsetªºÀ˵ø(¦pªG¸ê®Æ®w¤º¨S¦³²Å¦X¿ï¾Ü·Ç«hªº°O¿ý¡A«h¥i¥H¬OªÅ¥Õªº)¡F«áªÌ¬O´¡¤J¡B§R°£©Î­×§ï¸ê®Æ®w¤º­ÈªºSQL©R¥O©Î¹w¦sµ{§Ç¡A¦ý¤£·|¶Ç¦^°O¿ý¡C¨Ò¦p¡A§A¥i¥H«Ø¥ß¦W¬°AuthorsInCAªºª«¥ó¡AÅý¦¹ª«¥ó¨Ï¥Î¥H¤UªºSQL¬d¸ß¶Ç¦^©Ò¦³¦í¦bCaliforniaªº§@ªÌ¡G

SELECT * FROM Authors WHERE State = 'CA'


¡@

¹Ï8-19 §A¥i¥H±N¸ê®Æªí¡BÀ˵ø¡B©M¹w¦sµ{§Ç¥Ñ¸ê®ÆÀ˵øµøµ¡©ì¦²¦Ü DataEnvironment ³]­p¤u¨ã¤¤¥H«Ø¥ßCommandª«¥ó¡A¨Ã¥H¥kÁä«ö¤@¤Uª«¥ó¥HÅã¥Ü¦Û­qªºÄÝ©Ê­¶

©MConnectionª«¥ó¤£¦P¡ACommandª«¥ó©Ò¦³ªºÄݩʳ£¥i¥H¦b¦Û­qªºÄÝ©Ê­¶¤¤³]©w¡A§A±q¤£»Ý­nÅã¥Ü¤@¯ëªº ÄÝ©Ê µøµ¡¡C¦b ¤@¯ë ¼ÐÅÒ­¶¤¤¡A§A¥i¥H¿ï¾ÜCommand¹ïÀ³ªº¸ê®Æ®wª«¥ó¡Ð¸ê®Æªí¡BÀ˵ø¡B¹w¦sµ{§Ç¡Ð©ÎªÌ¿é¤J¬d¸ßªºSQL¤å¦r(§A¤]¥i¥H°õ¦æSQL Query Builder¥H«Ø¥ß¤¬°Ê¦¡ªº¬d¸ß)¡C

¦pªG§A¦³¤@­Ó¤@¯ëªº«D°Ñ¼Æ¡BµL¶¥¼h¬[ºcªº©R¥O¡A§A«K¥i¥Hª½¨ì¨ì[¶i¶¥]ÄÝ©Ê­¶¡A¦p¹Ï8-20¡C¦b§A¥i¥H¨M©w´å¼ÐªºÃþ«¬©M¦ì¸m¡B¹ê¦æÂê©wªºÃþ«¬¡B¥»¾÷§Ö¨úªº¤j¤p(¤]´N¬O¥Ñ¦øªA¾¹Åª¨ú°O¿ýªº¼Æ¥Ø)¡B©R¥Oªº¹O®É­È¡B¬d¸ßÀ³¶Ç¦^°O¿ýªº³Ì¤j¼Æ¡C§A¥i¥H¨Ï¥Î³Ì«á¤@­Ó­ÈÁקK¶Ç¦^¼Æ¤dµ§°O¿ýªº¬d¸ß¡C¦pªG§A¤£¤F¸Ñ¤j³¡¥÷¿ï¶µªº·N¸q®É¡A¤£¥²¾á¤ß¡F¥¦­Ì·|ª½±µ¹ïÀ³¨ìADO Recordset©MCommandª«¥óªºÄÝ©Ê¡A¦b§AŪ§¹ ²Ä13 ©M 14³¹ «K·|¤F¸Ñ¥¦­Ìªº¥\¯à¡C


¡@

¹Ï8-20 CommandÄÝ©Ê­¶ªº[¶i¶¥]¼ÐÅÒ­¶

¦¹¼ÐÅÒ­¶¤º°ß¤@¤£»PADOª½±µ¬ÛÃöªºÄݩʬORecordset Returning®Ö¨ú¤è¶ô¡C¤j³¡¥÷ªº®É­Ô¡ADataEnvironment³]­p¤u¨ã¯à°÷§PÂ_§A¬O§_¤w·s¼WRecordset¶Ç¦^©R¥O©Î¬O«DRecordset¶Ç¦^©R¥O¡F¦ý¦pªG¥¦°µ¤F¿ù»~ªº°²³]¡A§A¥i¥H¨Ï¥Î¦¹®Ö¨ú¤è¶ô¨Ó­×¥¿¡C

°Ñ¼Æ«¬©R¥O
¡@

¨Ï¥Î°Ñ¼Æ¥i¥HÅýCommandª«¥ó¼W¥[«Ü¦h¼u©Ê¡C§A¥i¥H«Ø¥ß¨âºØ°Ñ¼Æ«¬Commandª«¥ó¡G²Ä¤@ºØ¬O®Ú¾ÚSQL¬d¸ß¡A²Ä¤GºØ¬O®Ú¾Ú»P°Ñ¼Æ¦s©ñªºµ{§Ç¡C¨Ï¥Î²Ä¤@ºØ°Ñ¼Æ«¬©R¥O®É¡A§A¥²¶·¿é¤J°Ñ¼Æ«¬ªºSQL¬d¸ß¡A¨Ï¥Î°Ý¸¹°µ¬°°Ñ¼Æªº°t¸m³B¡C¨Ò¦p§A¥i¥H¨Ï¥Î¥H¤Uªº¬d¸ß«Ø¥ß¦W¬°AuthorsByStateªºCommandª«¥ó¡G

SELECT * FROM Authors WHERE State = ?

·í§A¦b ÄÝ©Ê ¹ï¸Ü¤è¶ôªº ¤@¯ë ¼ÐÅÒ­¶¤¤¿é¤J¦¹¬d¸ß«á¡A¤Á´«¨ì °Ñ¼Æ ¼ÐÅÒ­¶¨ÃÀˬdDataEnvironment¬O§_¤w¸g¨M©w±N¬d¸ß¤º§t¦b°Ñ¼Æ¤¤¡C¦b¦¹¼ÐÅÒ­¶¤º¡A§A¥i¥H¬°¨C¤@­Ó°Ñ¼Æ³]©w¦WºÙ¡A³]©w¥¦ªº¸ê®ÆÄÝ©Ê©M¤j¤pµ¥¡C¦b¦¹Ãþ¬d¸ß¤¤©Ò¦³ªº°Ñ¼Æ³£¬O¿é¥X°Ñ¼Æ¡C

­Y­n«Ø¥ß¹ïÀ³¨ì¹w¦sµ{§ÇªºCommandª«¥ó¡A§A¥i¥H«ö¤@¤U Insert Stored Procedure ¶s¨Ã¿ï¾Ü§A­n´¡¤Jªº¹w¦sµ{§Ç¡CDataEnvironment³q±`¯à°÷Â^¨ú¹w¦sµ{§Çªº»yªk¨Ã¥¿½TªºÂX®iCommandªºParameters¶°¦X¡C§AÀ³¸Óª`·N°Ñ¼Æªº¤è¦V¡A¦]¬°¦³®É­ÔDataEnvironment¨Ã¤£·|¥¿½TªºÃѧO¥X¿é¤J°Ñ¼Æ¡A§A¥²¶·¤â°Ê­×´_¥¦ªºDirectionÄÝ©Ê¡C¦¹¥~¡AÂù­«Àˬd©Ò¦³¬°«D¹s­Èªºstring°Ñ¼Æ¡C

DataEnvironment³]­p¤u¨ãªº¸ê®Æôµ²
¡@

DataEnvironment³]­p¤u¨ã¥i¥H°µ¬°ADO¸ê®Æ¨Ó·½¡A¦]¦¹¦b°õ¦æ¶¥¬q¤¤¥¦­Ì·|¥X²{¦b ÄÝ©Ê µøµ¡ªºDataSource²Õ¦X¤è¶ô¤º¡C·í§A±N¤@­Ó±±¨î¶µ»PDataEnvironment³]­p¤u¨ãôµ²®É¡A§A¤]¥²¶·±N¸ê®Æ·Pª¾±±¨î¶µªºDataMemberÄݩʳ]©w¬°§A­nôµ²ªºCommandª«¥óªº¦WºÙ¡C¥u¦³°O¿ý¶°-¶Ç¦^ªºCommandª«¥ó¥i¥H°µ¬°¸ê®Æ¨Ó·½¡C

Äæ¦ì©M®æ½u
¡@

§A¤£»Ý­n¦bªí³æ¤W¤â°Ê«Ø¥ß±±¨î¶µ¨Ã±N³o¨Ç±±¨î¶µ»PData-Environmentª«¥óôµ²¡A¦]¬°Visual Basic 6¤¹³\§A¥H©ì¦²ªº¤èªk°õ¦æ¨C¤@­Ó°Ê§@¡C­Y­n¤F¸Ñ¨Ï¥Î¦¹¥\¯à¦³¦h»òªºÂ²³æ¡A«h­n¶}±Ò¤@­Ó·sªºªí³æ¡A¦b DataEnvironment µøµ¡¤¤«ö¤@¤UCommandª«¥ó¡A¦A±N¥¦³]¸m¨ìªí³æ¤W¡C§A°¨¤W·|¬Ý¨ìªí³æ¤W·|¦³³\¦hTextBox±±¨î¶µ©MCheckBox±±¨î¶µ(¥i¯à)¡A¤@­Ó±±¨î¶µ¥NªíCommandª«¥ó¤º¨C¤@­ÓÄæ¦ì¡A¦p¹Ï8-21¡C§A¥i¥H«öF5¨ÓÀˬd¸ê®ÆªºÃ´µ²¾÷¨î¬O§_¥¿½T¹B§@¡C


¡@

¹Ï8-21 ±NCommandª«¥ó©ì¦²¦Üªí³æ©Ò«Ø¥ßªº¤@²Õôµ²±±¨î¶µ

¦]¬°¦bªí³æ¤W¨Ã¨S¦³Data±±¨î¶µ¡A§A¥²¶·´£¨Ñ¤@­Ó¨µÄýªº«ö¶s¡C¤èªk«D±`ªºÂ²³æ¡G¥u­n«Ø¥ß¨â­ÓCommandButton±±¨î¶µ¡A¤À§O©R¦W¬°cmdPrevious©McmdNext¡A¦A¥[¤J¥H¤Uªºµ{¦¡½X¡G

Private Sub cmdNext_Click()
    DataEnvironment1.rsAuthors.MoveNext
End Sub
Private Sub cmdPrevious_Click()
    DataEnvironment1.rsAuthors.MovePrevious
End Sub

¥Ñ©óDataEnvironment¬O¦b°õ¦æ¶¥¬q¤¤«Ø¥ß¡A¹ï©ó¨C¤@­Ó°O¿ý¶°-¶Ç¦^Commandª«¥ó¦Ó¨¥¡ARecordsetªº¦WºÙ¬Ors¤§«áªºCommand¦WºÙ¡C¨Ï¥Î¬Û¦Pªº¤èªk¡A§A¥i¥H¥[¤J§R°£©M´¡¤J°O¿ý¡B´M§ä­Èªº«ö¶sµ¥¡C¦p»ÝADO Recordsetª«¥ó©Ò¦³ªºÄÝ©Ê¡B¤èªk©M¨Æ¥ó¡A½Ð°Ñ¾\ ²Ä13 ©M 14³¹ ¡C

§A¤£­­©ó¥u¯à«Ø¥ß²³æªº±±¨î¶µ¡A§A¬Æ¦Ü¥i¥H¨Ï¥Îôµ²®æ½u¥HÅã¥Ü°O¿ýªºªí®æÀ˵ø¡C¦pªG§A­n¨Ï¥Îôµ²®æ½u¡A§A¥²¶·¥H·Æ¹«¥kÁä¨Ó¶}±Ò©ì©ñªº§@·~¡A·í´å¼Ð¥X²{¦bªí³æ¤§¤W®É©ñ¶}·Æ¹«¡A¦A¥Ñ§Ö³t¥\¯àªí¤¤¿ï¾Ü ¸ê®Æ®æ½u ¿ï¶µ¡C¹Ï8-22ªºÂ²³æµ{¦¡¥Ü½d¦p¦ó¨Ï¥Î°Ñ¼Æ«¬AuthorsByState©R¥OÅã¥Ü®æ½u¤º©Ò¦³°O¿ýªº¤l¶°¡C³o¬O¦b Filter «ö¶s¤§«áªºµ{¦¡½X¡G

Private Sub cmdFilter_Click()
     'Run the query¡Apassing the expected ixStatel  parameter.
    DataEnvironment1.AuthorsByState txtState
     'Ensure that the grid is bound to the DataEnvironment.
    Set DataGrid1.DataSource = DataEnvironment1
    DataGrid1.DataMember = "AuthorsByState"
End Sub

©ÎªÌ§A¥i¥Hª½±µ±N®æ½u»P¥Ñ°Ñ¼Æ«¬¬d¸ß©Ò²£¥ÍªºRecordsetôµ²¦b¤@°_¡G

Set DataGrid1.DataSource = DataEnvironment1.rsAuthorsByState


¡@

¹Ï8-22 ¦¹Â²³æªºÀ³¥Îµ{¦¡Åã¥ÜAuthors¸ê®Æªíªº°O¿ýÀ˵ø©M¸ê®ÆªíÀ˵ø¡A¥¦·|Åý§A¿z¿ïStateÄæ¦ìªº°O¿ý

¿ï¾ÜÄæ¦ìÃþ«¬
¡@

·í§A±NCommandª«¥ó(©Î¤@­Ó¸ê®Æ®wÄæ¦ì)³]¸m¦bªí³æ¤W®É¡A¨Ì·Ó¹w³]DataEnvironment³]­p¤u¨ã·|«Ø¥ß©Ò¦³Ãþ«¬Äæ¦ìªºTextBox±±¨î¶µ¡A°£¤FBooleanÄæ¦ìªºCheckBox±±¨î¶µ¡C§A¥i¥H¨Ì·Ó¥H¤Uªº¤èªkÅܧ󦹹w³]¦æ¬°¡G

¶¥¼h«¬©R¥O
¡@

DataEnvironment³]­p¤u¨ã´£¨ÑADO¦b³]­p¶¥¬q¤¤³Ì±j¤jªº¥\¯à¤§¤@¡A¤]´N¬O«Ø¥ß¶¥¼hRecordsetsªº©R¥O¡C¶¥¼hRecordset¥]§t¤@²Õ°O¿ý¡A³o¨Ç°O¿ý¥i¥]§t¨ä¥Lªº¤lRecordsets¡C¦³¤@­Ó¹ê»Úªº¨Ò¤l¥i¥H»¡©ú¬°¦ó³o¬O¤@¥ó¦n¨Æ¡G§Ú­Ì°²³]§A­n¥ÑBiblio.mdb¸ê®Æ®w¤¤«Ø¥ß§@ªÌªº²M³æ¡A¨C¤@­Ó§@ªÌ§A³£­nÅã¥Ü¥L©Ò¼gªº®Ñªº²M³æ¡C§A¥i¥H°õ¦æSQL JOIN¬d¸ß¥HÂ^¨ú¦¹¸ê°T¡F©ÎªÌ§A¥i¥H¤â°Êªº¤è¦¡¨ÓÂX¥RÅã¥Ü¦¹¥D­n/²Ó¸`Ãö«Yªºªí³æ¡A¤èªk¬O¨C¦¸¨Ï¥ÎªÌ¥ÑAuthors¥D¸ê®Æªí¤º²¾¨ì·sªº°O¿ý®É¡A«h°õ¦æTitle Author¸ê®Æªí©MTitles¸ê®ÆªíªºSQL SELECT¬d¸ß¡C¦ýµ§ªÌ¹ï³o¨â­Ó¤èªk³£¤£¬Æº¡·N¡A¤×¨ä¬O²{¦b§A¥i¥H¨Ï¥Î¶¥¼h«¬Recordset®É¡C²{¦bÅý§Ú¦V§A¤¶²Ð¥¦ªº¹B§@¤è¦¡¡C

Ãö«Y¶¥¼h
¡@

¦bDataEnvironment³]­p¤u¨ã¤¤«Ø¥ß¶¥¼h«¬Recordsetsªº¤èªk¦³«Ü¦h¡C²Ä¤@­Ó¤èªk»Ý­n§AÅã¥Ü»P¦¹Ãö«Y¤ºªº¥D¸ê®Æªí¹ïÀ³ªºCommandª«¥óªº Relation ÄÝ©Ê­¶¡C­Y­n¤F¸Ñ³o¨Ç§Þ³Nªº¹B§@¤è¦¡¡A¦b[¸ê®ÆÀ˵ø]µøµ¡¤¤¶}±Ò»PBiblio.mdb¸ê®Æ®wªº³s½u¡A¦A±NAuthors and Title Author¸ê®Æªí©ì¦²¨ìDataEnvironmentµøµ¡¤¤¡C­Y­nÅý«áªÌCommand¦¨¬°«eªÌªº¤l¶µ¥Ø¡A«hÅã¥ÜTitle_Authorª«¥óªºÄÝ©Ê­¶¨Ã¤Á´«¨ì[Relation]¼ÐÅÒ­¶(¦p¹Ï8-24)¡C

«ö¤@¤U Relate To a Parent Command Objec t®Ö¨ú¤è¶ô¥H±Ò¥Î¦¹ÄÝ©Ê­¶¤Wªº±±¨î¶µ¡A¦A¿ï¾Ü²Õ¦X¤è¶ôªºCommand(¥»¨Ò¤¤¬OAuthors)¤÷¶µ¥Ø¡C¦b Relation Definition ®Ø¬[¤¤¡A¿ï¾Ü¨â­ÓCommandª«¥ó¬ÛÃöªºÄæ¦ì¡C¦¹Äæ¦ì¬O¤÷Commandªº¥D­n¯Á¤ÞÁä©M¤lCommandªº¥~³¡¯Á¤ÞÁä¡C¦b³o­Ó½d¨Ò¤¤¡A³o¨â­ÓÄæ¦ì¦b³o¨â­Ó¸ê®Æªí¤¤¾Ö¦³¬Û¦Pªº¦WºÙ¡A¦ý³oºØ±¡ªp¨Ã¤£±`¨£¡C­Y­n§¹¦¨§Ú­Ìªº½d¨Ò¡A½T©wAu_ID¶µ¥Ø¦b¨â­Ó²Õ¦X¤è¶ô¤¤³£³Q¤Ï¥Õ¿ï¾Ü¡A«ö¤@¤U ·s¼W ¶s¥H¥[¤JÄæ¦ì²M³æ¤¤¡A¦A«ö¤@¤U ½T©w ¥H½T»{°Ê§@¡C§A·|ª`·N¨ìTitle_Author Command¤w¸g¦¨¬°Author Commandªº¤l¶µ¥Ø¡A»P¸û«áªÌªºÄæ¦ì¦ì©ó¦P¤@¼h¯Å¤¤¡C¨Æ¹ê¤W¡A·íDataEnvironment³]­p¤u¨ã¦b°õ¦æ¶¥¬q¤¤«Ø¥ß¦¹¶¥¼h«¬ªºRecordset®É¡A¥¦ªº²Ä4­ÓÄæ¦ì·|¯u¥¿ªº¥]§t¤lRecordset¡C


¡@

¹Ï8-24 Äݩʹï¸Ü¤è¶ôªº Relation ¼ÐÅÒ­¶

­Y­n§ïµ½½d¨Òµ{¦¡¡A§Ú­Ì»Ý­n«Ø¥ßTitles Command¨ÃÅý¥¦¦¨¬°Title_Authorª«¥óªº¤l¶µ¥Ø¡C¦b¦¹§Ú­Ì¨Ï¥Î¥t¤@ºØ¤£¦Pªº¤èªk¡G¥H¥kÁä«ö¤@¤UTitle_Author Command¡A¿ï¾Ü[Add Child Command]ª«¥ó¡C¦p¦¹·|«Ø¥ß¤@­Ó¦W¬°Command1ªºª«¥ó¡C±N¦¹ª«¥ó­«·s©R¦W¬°Titles¡A¶}±Ò¥¦ªºÄÝ©Ê­¶¡A«ü©w¦¹ª«¥ó¥ÑBiblio.mdb¸ê®Æ®wªºAuthors¸ê®Æªí¤¤Â^¨ú°O¿ý¡A¦A¤Á´«¨ì[Relation]¼ÐÅÒ­¶¥H§¹¦¨Ãö«Y¡CTitle_Author©MTitles Com-mands»P¥¦­ÌªºISBNÄæ¦ì¬ÛÃö¡A¦]¦¹§A­n«ö¤@¤U[·s¼W]¶s¨ÃÃö³¬¹ï¸Ü¤è¶ô¡C§A¤w¸g§¹¦¨3¼h¶¥¼h«¬Recordsetªº«Ø¥ß¡C

­Y­n´ú¸Õ³o­Ó·sªºª«¥ó¡A«Ø¥ß·sªºªí³æ¡A¨Ï¥Î·Æ¹«¥kÁä±NAuthors Command©ì¦²¦Üªí³æ¤W¡A¨Ã¿ï¾Ü¥\¯àªí¤Wªº[Hierarchical Flex Grid]¡C¦p¦¹¥i¥H¦bªí³æ¤W«Ø¥ßMicrosoft Hierarchical FlexGrid±±¨î¶µªº¨Ò¶µ¡A§A»Ý­nÅý¤@¨ÇÄæ¦ì¬Ý¤£¨£¡A¦]¦¹§AÀ³¸Ó¥H¥kÁä«ö¤@¤U®æ½u¡A¿ï¾Ü Retrieve Structure ¡A¦A¦¸¥H¥kÁä«ö¤@¤U¥HÅã¥Ü[ÄÝ©Ê]¹ï¸Ü¤è¶ô¡A¨Ã¤Á´«¨ì Bands ¼ÐÅÒ­¶¡C¦b¦¹¼ÐÅÒ­¶¤W¡A§A¥i¥H©w¸q¦b¦¹Ãö«Y¤¤ªº3­ÓRecordsets¥i¥HÅã¥Ü­þ¤@¨ÇÄæ¦ì¡C¦b Band 0 (Authors) ¤¤¡A²M°£Au_ID®Ö¨ú¤è¶ô¡F¦b Band 1 (Title_Author) ¤¤¡A²M°£ISBN©MAu_ID®Ö¨ú¤è¶ô(¦p¦¹·|ÅýBand¬Ý¤£¨£)¡F¦b Band 2 (Titles) ¤¤¡A²M°£Pub_ID¡BDescription¡BNotes¡B©MComments®Ö¨ú¤è¶ô¡C§A²{¦b¥i¥H°õ¦æÀ³¥Îµ{¦¡¡Aµ²ªGÀ³¸Ó¦p¹Ï8-25¡Cª`·N§A¥i¥H¨Ï¥Î¾aªñ®æ½u¥ªÃä¬Éªº¥[©M´îªº²Å¸¹¥H®i¶}©MºPÅ|¨C¤@¦æ¡C

§A¥i¥H¬°¦¹½d¨Ò·s¼W¥t¤@¼hªº¶¥¼h¡A¦¹¶¥¼hÅã¥Ü¨C¤@¥»®Ñªº¥Xª©°Ó¸ê°T¡F·s¼W¼h¯Åªº¤èªk¬O±NPublishers¸ê®Æªí¥Ñ ¸ê®ÆÀ˵ø µøµ¡©ì¦²¦ÜData-Environment³]­p¤u¨ã¤¤¡AÅý¥¦¦¨¬°Titles Commandªº¤lComman¡C³o¤@³¡¥÷´N¯d«Ý§A¦Û¤v½m²ß¡C


¡@

¹Ï8-25 Hierarchical FlexGrid±±¨î¶µÅã¥Ü¶¥¼h«¬ªºRecordsets¡A¨ÃÅý§A®i¶}©MºPÅ|¤÷Recordset­Ó§Oªº¸ê®Æ¦æ

¸s²Õ¶¥¼h
¡@

DataEnvironment³]­p¤u¨ã¤ä´©¨âºØªº¶¥¼hÃþ«¬¡GGrouping©MAggregate¶¥¼h¡C¸s²Õ¶¥¼h¦b·§©À¤W«Ü²³æ¡G§A«Ø¥ß¤@­ÓCommandª«¥ó¨Ã«Ø¥ß¤@­Ó¤÷Command¡AÅý¦¹¤÷¶µ¥Ø¯à¨Ì¾Ú¦h­ÓÄæ¦ì¸s²Õ­ì©lCommandªº°O¿ý¡C­Y­n·Q­n¹ê»Ú¤F¸Ñ¥¦ªº·N¸q¡A±NTitles¸ê®Æªí©ì©ñ¦ÜDataEnvironmentµøµ¡¤¤¡A¶}±Ò¥¦ªº Grouping ÄÝ©Ê­¶¡A¿ï¾Ü Group Command Object ®Ö¨ú¤è¶ô¥H±Ò¥Î¦¹¼ÐÅÒ­¶¤Wªº±±¨î¶µ¡A±N Year Published Äæ¦ì¥Ñ¥ª²M³æ¤è¶ô·h²¾¨ì¥k²M³æ¤è¶ô¤¤¡A¦A±N¹ï¸Ü¤è¶ôÃö³¬¥H½T»{§AªºÅܧó¡C§A·|¬Ý¨ìData-Environment³]­p¤u¨ã²{¦b¦b¥DConnection¤§¤U¸Ë¸ü¤F¤@­Ó·sªºCommandª«¥ó¡A¦WºÙ¬°Titles1_grouped_using_Title1_Grouping¡A¦b¥¦ªº¤U¤è¦³¨â­Ó¸ê®Æ§¨¡C¤@­Ó¸ê®Æ§¨¤º¥]§tYear PublishedÄæ¦ì(ºK­nÄæ¦ì)¡A¥t¤@­Ó¸ê®Æ§¨¥]§t­ì©lTitles1 CommandªºÄæ¦ì¡C¦pªG§A­n±NHierarchical FlexGrid±±¨î¶µ»P·sªº¤÷Commandôµ²¡A§A·|¬Ý¨ì³Ì¥ª¤èªºÄæ¦ì¤ºÅã¥Ü¤£¦Pªº¦~¥÷¡A¦Ó¨ä¥LªºÄæ¦ì¤º¥]§t¸Ó¦~¥X®Ñªº¥Xª©°Ó¸ê°T¡C

·JÁ`¶¥¼h
¡@

·JÁ`Äæ¦ì¬O­pºâÄæ¦ì¡A¥¦·|­pºâRecordset©Ò¦³¸ê®Æ¦æ«ü©wÄæ¦ìªº¹Bºâ¦¡(­p¼Æ¡BÁ`©M¡B¥­§¡µ¥)¡C·í§A¤w¸g¦³¸s²Õ¶¥¼h®É¡A§A³q±`·|·s¼W¤@­Ó·JÁ`Äæ¦ì¡C´N§Ú­Ìªº½d¨Ò¦Ó¨¥¡A§Ú­Ì·s¼W¤@­ÓTitleCountÄæ¦ì³ø§i¨C¤@¦~¥Xª©®Ñªº¼Æ¶q¡C¦b¸û½ÆÂøªº½d¨Ò¤¤¡A§A¥i¯à·|±N©Ò¦³ªº­q³æ¨Ì¤ë¥÷¸s²Õ¡A¨Ã¥[¤W¼Æ­Ó·JÁ`Äæ¦ì¨Ó³ø§i­q³æªº­p¼Æ¡B­q³æªºÁ`­p¡B¥­§¡µ¥¡C

§A¥i¥H¦b ÄÝ©Ê ¹ï¸Ü²°¤ºªº Aggregates ¼ÐÅÒ­¶¤¤©w¸q·JÁ`Äæ¦ì¡C«ö¤@¤U ·s¼W ¶s¥H«Ø¥ß·sªº·JÁ`Äæ¦ì¡A¬°¦¹Äæ¦ì³]©w¤@­Ó¦³·N¸qªº¦WºÙ¡A¥Ñ¥H¤Uªº¨ç¼Æ¤¤¿ï¾Ü¤@­Ó¡GCOUNT¡BSUM¡BAVERAGE¡BMINIMUM¡BMAXIMUM¡BSTANDARD DEVIATION¡B©ÎANY(ANY·|¶Ç¦^³Q¿ï¾Ü°O¿ý¤¤©Ò¦³Äæ¦ì¦@¦Pªº­È)¡C Aggregate On ²Õ¦X¤è¶ô¥i¥H¨M©w­þ¤@­ÓÄæ¦ì¥Ñ·JÁ`Äæ¦ì¨Ó­pºâ¡A¨Ã¦¨¬°¡GGrouping¡BGrand Total¡B©Î¤lCommandªº¦WºÙ(²Õ¦X¤è¶ô¹ê»Úªº¤º®e¨ú¨M©ó¥Ø«eCommandªºÃþ«¬)¡C¦pªG§A¿ï¾ÜGrand Total¡A§A¥i¥H¿é¤JÁ`­pÄæ¦ìªº¦WºÙ¡C¦b¦¹±¡ªp¤U¡A¦b¥DCommand¤§¤U·|«Ø¥ß·sªº¸ê®Æ§¨¡A¥¦·|»E¶°¦bCommand¤º©Ò¦³ªºÁ`­pÄæ¦ì(¦p¹Ï8-26)¡C


¡@

¹Ï8-26 ¨Ï¥Î¤TºØ¶¥¼hÃþ«¬ªºCommandª«¥ó

SQL»y¨¥
¡@

¦pªG§A­n¨Ï¥Î¸ê®Æ®w¡A§A¥²¶·¾Ç·|¥¦ªº»y¨¥¡C¸ê®Æ®w¨Ï¥Îªº¬OStructured Query Language»y¨¥¡A¤]´N¬OSQL¡A¦b1970¦~¥N¥ÑE. F. Coddµo©ú¡CSQL¨Ã¤£¬O¤@¦¸¥u¾Þ§@¸ê®Æªí¤¤ªº¤@µ§°O¿ý¡A¦Ó¬O±N¤@²Õ°O¿ýµø¬°¦P¤@­Ó¨Ò¶µ¨ÓºÞ²z¡A¨ÏSQL§ó¾A©ó«Ø¥ß¥ô¦ó½ÆÂøªº¬d¸ß¡C¦¹»y¨¥¤w¸g³Q¼Ð·Ç¤Æ¡A²{¦b¤j³¡¥÷ªº¸ê®Æ®w¦øªA¾¹(©MADO¥»¨­)³£±µ¨üANSI-92¡CSQL±N¨âºØ¤£¦Pªº±Ô­z¡G¸ê®Æ©w¸q»y¨¥(Data Definition Language¡ADDL)©M¸ê®Æ¾Þ§@»y¨¥(Data Manipulation Language¡ADML)¡CDDL¦r¶°¥]¬A¤F¤@²Õ±Ô­z¡A¦¹±Ô­z¥iÅý§A«Ø¥ß¸ê®Æµ²ºc¡A¦p¸ê®Æªí¡BÄæ¦ìµ¥¡CDML¤l¶°¥]¬A©Ò¦³¤¹³\§A¬d¸ß©M­×§ï¸ê®Æ®w¡B·s¼W·sªº°O¿ý¡B©Î§R°£²{¦³°O¿ýªº©R¥O¡C

¦³¼Æ¤£ºÉªº®Ñ´¿¼g¨ì¦³ÃöSQLªº³¡¤À¡A©Ò¥H·|ºÉ¥i¯àªº¼g¥X¨Ó¦³ÃöSQL·sªº¥\¯à¡C¦ý¬O§Ú¼g³o­Ó³¹¸`¥u¬OÅý±q¥¼¨Ï¥Î¹L¸ê®Æ®wªº±z¥h¤F¸ÑSQL¬d¸ß¡A¦pªG±z¤w¸gºë³qSQL±z¥i¥H¤£¥Î¿ðºÃªº¸õ¨ì¤U¤@³¹¡C

¥»³¹¸`¤j¦hªº½d¨Ò³£¨Ï¥ÎBiblio.mdb©ÎNWind.mdb¸ê®Æ®w¡A¦b¥úºÐ¤ù¤¤¡A±z±N¥iµo²{¤@­Ó½d¨ÒÀ³¥Îµ{¦¡¡]¦p¹Ï8-27¡^³o­Ó½d¨Ò¥i¥HÅý±z½m²ßSQL¤Î°¨¤W¬Ý¨ì±z¬d¸ßªºµ²ªG¡A±z¥i¥H¥Î¡u<¡v¡u>¡v«ö¶s¨Ó­«½Æ¨Ï¥Î¤W­Ó¬d¸ß¡A±z¤]¥i¥Hµo²{±z¥i¥H¦w¥þªº°õ¦æ¬d¸ß¦pdelete¡Binsert©Î¬O­×§ï¬ö¿ý¡A¦]¬°±zªº°Ê§@¥þ³¡·|³Q©ñ¨ì¥æ©ö°O¿ý¤¤¡A±z¥i¥HÃö³¬³o­Óªí³æ¦Ó³o¨Ç¥æ©ö°O¿ý³£·|³Q­Ë¦^¦Ó¤£·|¯}Ãa­ì¨Óªº¸ê®Æ®w¡C


¡@

¹Ï8-27 SQL Training½d¨Òµ{¦¡

SELECT©R¥O
¡@

³Ì±`¨Ï¥ÎSQL±Ô­z¥yµLºÃªº´N¬OSELECT©R¥O¡A¥¦¥i¥H¦^¶Ç¤@²Õ¿ï¨úªº°O¿ý¡C

°ò¥»¿ï¨ú
¡@

²³æªºSELECT©R¥O±q¸ê®Æ®w¦^¶Çªí³æ¤¤©Ò¦³ªº°O¿ý©M©Ò¦³ªºÄæ¦ì¡G

SELECT * FROM Publishers

¡]¦b³o­Ó³¹¸`¤¤©Ò¦³ªº½d¨Ò¡ASQLªº«ü¥O³£¨Ï¥Î¤j¼gªí¥Ü¡A¦ý¬O¦pªG±z³ßÅw±z¥i¥H¥Î¤p¼g¡^±z¥i¥H¥Î«ü©wÄæ¦ìªº¤èªk¬d¸ß±z©Ò­n¬ÝªºÄæ¦ì¡A¦pªGÄæ¦ì¦W¦r¤¤¥]§tªÅ¥Õ©Î¬O¨ä¥Lªº²Å¸¹¡A´N¥²¶·¥Î¡u[]¡v¬A°_¨Ó¡C

SELECT PubID, [Company Name], Address FROM Publishers

±z¥i¥H¥u¬d¸ß±zªºÀ³¥Îµ{¦¡­n¥ÎªºÄæ¦ì¨Ó´£ª@¬d¸ßªº³t«×¡ASQL¦bSELECTÄæ¦ìªº³¡¤À¤ä´©Â²³æªº¹Bºâ¡A¨Ò¦p¡G±q¦è¤¸¥X¥Í¦~ºâ¥X¨C­Ó§@ªÌªº¦~ÄÖ¡C

SELECT Author, 2000-[Year Born] AS Age FROM Authors

½Ðª`·NAS¤l¥yÅý±z½á¤©¤@­Ó®e©öºÙ©Iªº¦W¦rµ¹­pºâÄæ¦ì¡C±z¤]¥i¥H¥Î¶°¦X¨ç¼Æ¦p¡GCOUNT¡BMIN¡BMAX¡BSUM©MAVG´N¹³³o­Ó½d¨Ò¤@¼Ë¡G

SELECT COUNT(*) AS AuthorCnt, AVG(2000-[Year Born]) AS AvgAge FROM Authors

³o¥y±Ô­z·|¶Ç¦^¶È¦³¨â­ÓÄæ¦ìªº¤@µ§¸ê®Æ¡GAuthorCnt¬O¸ê®Æªíªº°O¿ý§Ç¸¹¡A

AvgAge¬O¦b¤½¤¸¨â¤d¦~©Ò¦³§@®aªº¥­§¡¦~ÄÖ¡C

¶°¦X¨ç¼Æ¤@¯ë¦Ó¨¥¥u¦Ò¼{¸ê®Æ®w¤¤«DNullªº­È¡A¨Ò¦p¡A±z¥i¥H¸ÕµÛ±N§@ªÌ¤¤¦³¥X¥Í¦~¸ê®Æªº¤H¼Æºâ¥X....

SELECT COUNT([Year Born]) FROM Authors

Count(*)»yªk¬O¤@­Ó¤@¯ë³W«hªº¹Bºâ¦¡¡A¥¦·|¶Ç¦^¤@­Ó©Ò¦³µ§¼ÆªºÁ`¼Æ¶q¡C¦b¯u¹êªºÀ³¥Îµ{¦¡¤¤¡A±z«Ü¤Ö·|¨ú¦^¸ê®Æªí¤¤©Ò¦³ªº¸ê®Æ¡A¥D­nªº²z¥Ñ¬O¡G¦pªG¸ê®Æªí¤¤¥]§tµÛ¤W¤dµ§ªº¸ê®Æ¿ý¡A¨º´N·|¦û¥Î¤Ó¦hªººô¸ô¸ê·½¡A±z¥i¥H¥ÎWHERE¤l¥y¨Ó¿z¿ï³¡¤Àªº¸ê®Æ¡C¨Ò¦p¡A¨ú¦^©Ò¦³¦bCaliforniaªº¥Xª©°Ó

SELECT Name, City FROM Publishers WHERE State = 'CA'

§Ú­ÌÁÙ¥i¥H¥Îµ²¦X¥¬ªL¹BºâAND©MOR±ø¥ó¥y´N¹³¬O¤U¦Cªº¬d¸ß¡A¤U­Ó¥y¤l¦^¶Ç¤F¦bCalifornia¦W¦r¬°M¶}ÀYªº¥Xª©°Ó¡G

SELECT * FROM Publishers WHERE State = 'CA' AND Name LIKE 'M%'

¦bWHERE¤l¥y¤¤¡A±z¥i¥H¥Î©Ò¦³ªº¤ñ¸û¹Bºâ¤l¡]=¡B<¡B<=¡B>¡B>=¡B©M<>¡^©MLIKE¡BBETWEEN¤ÎIN¹Bºâ¤l¡CBETWEEN¹Bºâ¤l¸g±`¥Î¦b¿ï¥X¦b¤@­Ó½d³ò¤¤ªº©Ò¦³­È¡G

SELECT * FROM Titles WHERE [Year Published] BETWEEN 1996 AND 1998

IN¹Bºâ¤l¦b±z§ä¥X¤@¨Ç­Èªº²M³æ¤¤¬O¬Û·í¦³¥Îªº¡C¤U¦Cªº¨Ò¤l¶Ç¦^©Ò¦³¦ì©óCalifornia¡BTexas¡BNew Jerseyªº¥Xª©°Ó¡C

SELECT Name, State FROM Publishers WHERE State IN ('CA', 'TX', 'NJ')

SQLÅý±z¨Ï¥Î³æ¤Þ¸¹©ÎÂù¤Þ¸¹ªí¥Ü¦r¦ê¡A¦]¬°±z¸g±`·|¶Ç³o¨Ç¥y¤l·í§@Visual Basic¦r¦ê¡A©Ò¥H¤j¦h¼Æªº®É­Ô¥Î¨â­Ó¹ïºÙªº³æ¤Þ¸¹¨Óªí¥Ü¤@­Ó¦r¦ê¡A¨Ò¦p¡A·j´M§@ªÌ¦W¦r¬°¡uO'Hara¡v¡A±z¥²¶·¥Î¤U¦Cªº¬d¸ß¡G

SELECT * FROM Authors WHERE Author = 'O''Hara'

±Æ§Ç¤Î¸s²Õ
¡@

ORDER BY¤l¥yÅý±z¹ï¦^¶Çªº¸ê®Æ§@±Æ§ÇªºÄæ¦ì¡C±z¥i¥HÅã¥Ü¸ê®Æ«ö·Ó¥Xª©°Óªº¦r¥À±Æ¦C¡G

SELECT * FROM Publishers ORDER BY [Company Name]

±z¤]¥i¥H¥Î³r¸¹«ü©w¦h­Ó±Æ§ÇªºÁä­ÈÄæ¦ì¡A¨C­Ó±Æ§ÇÁä­È¥i¥H¥ÎDESCÃöÁä¦r§@­°¾­±Æ§Ç¡C¨Ò¦p¡A±z¥i¥H¦C¥X¥Xª©°Ó¥Îstate§@¤É¾­±Æ§Ç¦P®É¦C¥X©Ò¦³¦b¦P¤@­Ó¦{ªº«ö·Ócity§@­°¾­±Æ§Ç¡A¦p¦P¤U­±ªº¥y¤l¡C¡]¤@¯ë¨Ó»¡³o½d¨Ò¬O¨S¦³¤°»ò¥Îªº¡A ¥u¬O¥Î¨Ó°µ½d¨Ò½}¤F¡^¡C

SELECT * FROM Publishers ORDER BY State, City DESC

·í¦^¶Çªº¸ê®Æ±Æ§Ç«á¡A±z¥i¥H¥ÎSELECTªºTOP¤l¥y¨ú¦^«e´X­Ó±Æ§Çªº°O¿ý¡A¨Ò¦p¡G¥Î¤U­±ªº¬d¸ß¨ú¦^«e5µ§°O¿ý¡G

SELECT TOP 5 * FROM Titles ORDER BY [Year Published] DESC

½Ð°O¦íTOP¤l¥y·|«ö·Ó±zµ¹ªº­È¶Ç¦^±Æ§Ç«áªº¸ê®Æ¼Æ¶q¡A¨Ò¦p¡G§Ú­Ì¥i¥H¥ÎTOP PERCENT©w¸qÁ`¦^¶Ç¼Æ¶qªº¦Ê¤À¤ñ¡G

SELECT TOP 10 PERCENT * FROM Titles ORDER BY [Year Published] DESC

GROUP BY¤l¥yÅý§Ú­Ì«Ø¥ß¥]§t¤F¸ê®Æ°O¿ýªº¸s²Õ¤¤ªººK­n¬ö¿ý¡A¨Ò¦p¡G±z¥i¥H§@¤@­Ó¦U¦~µo¦æ®Ñªº¼Æ¶q¡G

SELECT [Year Published], COUNT(*) As TitlesInYear FROM Titles 
    GROUP BY [Year Published]

¤U¤@­Ó¬d¸ß¥i¥HÅã¥Ü¦b³Ìªñ¤Q¦~¦U¦~µo¦æ®Ñªº¼Æ¶q¡G

SELECT TOP 10 [Year Published], COUNT(*) As TitlesInYear FROM Titles 
    GROUP BY [Year Published] ORDER BY [Year Published] DESC

§Ú­Ì¥i¥H¥ÎHAVING¨ÓÀu¶®ªº¨Ï¥ÎGROUP¡A³o­Ó¤l¥yÃþ¦üWHERE¡A¦ý¬O¥¦¥Î¦bGROUP BY¥y¤l¤§«á¡C¤U­Ó¬d¸ßÃþ¦ü¤W­Ó¨Ò¤l¡A¦ý¬O¥u¦^¶Ç¥Xª©¶W¹L50¥»ªº®Ñ°Ó¡G

SELECT [Year Published], COUNT(*) As TitlesInYear FROM Titles 
    GROUP BY [Year Published] HAVING COUNT(*)  > 50

±z¥i¥H¦b¦P¤@­Ó¬d¸ß¤¤¦P®É¨Ï¥ÎWHERE©MHAVING¤l¥y¡A¦P®É¨Ï¥Î®É¡ASQL¥ÎWHERE¤l¥y¥ý¹LÂo­ì©lªº¸ê®Æªí¦A¥ÎGROUP BY¤l¥y«Ø¥ß¸s²Õ³Ì«á¦A¥ÎHAVING¤l¥y¹LÂo¤£²Å¦X¸s²Õ¸ê®Æ°O¿ý¡C

¤U­±ªº¥y¤l¶Ç¦^©Ò¦³¥Xª©°Óªº«°¥«¡G

SELECT City FROM Publishers

¤W­±³o­Ó¬d¸ß¶Ç¦^CityÄæ¦ì¨ä¤¤¦³¨ÇÄæ¦ì¬ONull¡A³o±N·|²£¥Í¤@¨Ç°ÝÃD¡Cªþ¥[¤@ÂI¦pªG¦³¨â­Ó¥Xª©°Ó¦b¦P¤@­Ó«°¥«®É¥¦±N¶Ç¦^¶W¹L¤@­Ó«°¥«¡A§Ú­Ì¥i¥H¥ý¨Ï¥ÎISNULL¨ç¼Æ¸Ñ¨M²Ä¤@­Ó°ÝÃD¡AµM«á¥ÎÃöÁä¦rDISTINCT¥h±¼­«½Æªº«°¥«¡C

SELECT DISTINCT City FROM Publishers WHERE NOT ISNULL(City)

¤l¬d¸ß
¡@

¦b§Úµ¹¤j®a¬Ýªºªº½d¨Ò¤¤¡A³£¥u¦³¨ú¦^¤@­Ó¸ê®Æªíªº¸ê®Æ¡A¦ý¦b¤j³¡¤Àªº®É­Ô¡A±z¤]·|¹ï¦h­Ó¸ê®Æªíªº¸ê®Æ¦³¿³½ì¡C¨Ò¦p¡G­n¦C¥X®Ñ¦W©M¥Xª©°Ó®É±z´N¥²¶·¦P®É¦s¨úTitles©MPublishers³o¨â­Ó¸ê®Æªí¡A¥u­n²³æªº¦bFROM¤l¥y¤¤«ü©w³o¨â­Ó¸ê®Æªíªº¦W¦r¡AµM«á³]©w¤@¾A¦XªºWHERE¤l¥y´N¥i¥H¤F¡C

SELECT Titles.Title, Publishers.Name FROM Titles, Publishers 
    WHERE Titles.PubID = Publishers.PubID

·í¨â¸ê®ÆªíÄæ¦ì¦³¬Û¦P¦WºÙ®É¡A¥²¶·¨Ï¥Îtablename.fieldname»yªkÁקK¼Ò¸W¨â¥i¡A³o¸Ì¦³¥t¤@­Ó½d¨Ò¡A±q«ü©wªº¥Xª©°Ó¤¤§ä¥X©Ò¦³ªº®Ñ¦W¡A±z¥²¶·¦bFROM¤l¥y¤¤«ü©w¨â­Óªí®æ¡A§Y¨Ï±z¥u±qTitles¸ê®Æªí¤¤¥h±o¨ì¸ê®Æ¡G

SELECT Titles.* FROM Titles, Publishers WHERE Publishers.Name = 'MACMILLAN'

±z¤]¥i¥H¥Î¥t¤@ºØ¤èªk§ó¦³®Äªº¨ú±o¬Û¦Pªº¸ê°T¡A«ö·Ó¹ê»Úªº±¡ªp¥ÎSELECT¥y¤lªº¡u=¡v¹Bºâ¤l¶Ç¦^¤@­Ó­Èµ¹¥ª¤èªº¥y¤l¡A³o­Ó¬d¸ß¥Î¤@­Ó±_ª¬ªºSELECT¬d¸ß¨ú±oµ¹¤©ªº¥Xª©°Ó©Ò¥Xª©ªº®Ñ¦W¡G

SELECT * FROM Titles WHERE PubID = 
    (SELECT PubID FROM Publishers WHERE Name = 'MACMILLAN')

¦pªG±z¤£½T©w¤l¬d¸ß¶Ç¦^ªº¬O§_¶È¬°¤@­Ó°O¿ý¡A¥i¥H¨Ï¥ÎIN¹Bºâ¤l¥N´Àµ¥¸¹¡A ±z¥i¥H«ö·Ó±z©Ò»Ý­nªº§â¤l¬d¸ßÅܪº½ÆÂø¤@ÂI¡A¨Ò¦p¡G±qCalifornia¡BTexas©MNew Jerseyªº¥Xª©°Ó¦C¥X¥L­Ì¥Xª©ªº®Ñªº¸ê®Æ¡G

SELECT * FROM Titles WHERE PubId IN 
    (SELECT PubID FROM Publishers WHERE State IN ('CA', 'TX', 'NJ'))

±z¤]¥i¥H¥ÎÁ`©M¨ç¼Æ¡A¦pSUM©ÎAVG¡A¤U¤@­Ó¬d¸ß¤¤·|¶Ç¦^Nwind.mdb¸ê®Æ®w¤¤©Ò¦³Orders¸ê®Æªí¤¤¤j©ó¹B¶O¥­§¡­Èªº¹B¶O¡G

SELECT * FROM Orders WHERE Freight > (SELECT AVG(Freight) FROM Orders)

Joins
¡@

join¹Bºâ¤l¸g±`¥Î¦b·Q­n³z¹L¨â­Ó¬ÛÃöÁp¸ê®Æªí¤¤¦@³qªºÄæ¦ì¨ú±o¸ê®Æ¡A¦bÆ[©À¤W´N¦n¹³¬O¥Ñjoin¶°¦X²Ä¤@­Ó¸ê®Æªí¤¤¤@¨Ç©Î©Ò¦³Äæ¦ì¸òÀH²Ä¤G­Ó¸ê®Æªí¤¤¤@¨Ç©Î©Ò¦³ªºÄæ¦ì¡A²Õ¦¨¬°¤@­Ó·sªº¸ê®Æªí¡F¦b¤@­ÓJOIN©R¥O¤¤¹Bºâ¦¡ON¤l¥y¨M©w­þ¤@­Ó²Ä¤G¸ê®ÆÄæ±N»Ý­n©M²Ä¤@­Ó¸ê®Æªíªº¸ê®Æ²Å¦X¡C¨Ò¦p¡G¤U­±ªº¬d¸ß¶Ç¦^©Ò¦³®Ñ¦W¤Î¥Xª©°Ó¦W¦rªº¸ê°T¡G

SELECT Titles.Title, Titles.[Year Published], Publishers.Name FROM Titles 
    INNER JOIN Publishers ON Titles.PubID = Publishers.PubID

¦³¤@­Ó­«­nªº²Ó¸`¡G¤W­Ó¥y¤l¤¤¥uÂ^¨ú®Ñ¦Wªº¥Xª©°Ó¡A¤]´N¬O»¡PubIDÄæ¦ì¤£¬ONull¡AINNER JOIN¡]´N¹³¬Oequi-join¡^¬O³Ì±`¥Îªºjoin¹Bºâ¤l¡ASQL¤]¤ä´©¨â­Ó¨ä¥L¤£¦PºØÃþªºjoins¡ALEFT JOIN©MRIGHT JOIN¹Bºâ¤l¡CLEFT JOIN¹Bºâ¤l¨ú¦^©Ò¦³¦b²Ä¤@­Ó¸ê®Æªíªº©Ò¦³¸ê®Æ¡A¤£ºÞ¬O§_¦³¹ïÀ³ªº¸ê®Æ¦b¨ä¥Lªº¸ê®Æªí¤¤¡C¨Ò¦p¡A¤U­±ªº©R¥O¨ú¦^©Ò¦³ªº®Ñ¦W§Y¨Ï¤£ª¾¹D¥Xª©°Ó¬O½Ö¡G

SELECT Titles.Title, Titles.[Year Published], Publishers.Name FROM Titles 
    LEFT JOIN Publishers ON Titles.PubID = Publishers.PubID

RIGHT JOIN¹Bºâ¤l¨ú¦^©Ò¦³¦b²Ä¤G­Ó¸ê®Æªí¤¤ªº¸ê®Æ¡A¬Æ¦Ü©M²Ä¤@­Ó¸ê®Æªí¨S¦³¬ÛÃöªº¸ê®Æ¡A¤U­±ªº½d¨Ò¦C¥X©Ò¦³ªº¥Xª©°Ó¡A¤£ºÞ¥¦¬O¤£¬O¦³¥Xª©¥ô¦óªº®Ñ¡G

SELECT Titles.Title, Titles.[Year Published], Publishers.Name FROM Titles 
    RIGHT JOIN Publishers ON Titles.PubID = Publishers.PubID

Join¹Bºâ¤l¥i¥H±_ª¬¤Æ¡A³o¸Ì¦³¤@­Ó½d¨Ò¨ú¦^©Ò¦³§@ªÌ©M¥L­Ì¼gªº®Ñªº¸ê°T¡A¨â­Ó¸ê®Æªí³z¹L¤¤¤¶ªºTitleAuthor¸ê®Æªí¬ÛÃö³s¡A©Ò¥H§Ú­Ì»Ý­n¤@­Ó±_ª¬ªºINNER JOIN¹Bºâ¤l¡G

SELECT Author, Title, [Year Published] FROM Authors INNER JOIN 
    ([Title Author] INNER JOIN Titles ON [Title Author].ISBN = Titles.ISBN) 
    ON Authors.Au_Id = [Title Author].Au_ID

·íµM¡A±z¥i¥H¥ÎWHERE¦b±_ª¬©M¥~°éªºJOIN¹LÂo¸ê®Æ¡A¨Ò¦p¡G±z¥i¥H¨ú±o1960¦~¤§«e¥Xª©ªº®Ñ¡G

SELECT Author, Title, [Year Published] FROM Authors INNER JOIN 
    ([Title Author] LEFT JOIN Titles ON [Title Author].ISBN = Titles.ISBN) 
    ON Authors.Au_Id = [Title Author].Au_ID WHERE [Year Published] < 1960

Unions
¡@

±z¥i¥H¨Ï¥ÎUNIONÃöÁä¦r¥[¤W¤@­ÓSELECT©R¥O¥H¨ú±o¤@­Óµ²ªG¡A¤]´N¬O»¡±z·Q°Ý­Ô±zªº«È¤á©M¨ÑÀ³°Ó¸t½Ï¸`§Ö¼Ö¡A±z¥i¥H¨ú±o¥L­Ìªº¦W¦r©M¦a§}´N¹³¤U­±¤@¼Ë¡G

SELECT Name, Address, City FROM Customers 
    UNION SELECT CompanyName, Address, City FROM Suppliers

³o¨â­Ó¸ê®Æªí¥i¥H¦³¤£¦Pªº¸ê®Æªíµ²ºc¡A´£¨ÑÄæ¦ìµ¹SELECT¬Û¦Pªº¸ê®Æ«¬ºA¡C

INSERT INTO©R¥O
¡@

INSERT INTO©R¥O´N¬O¥[¤J¤@µ§°O¿ý¨ì¸ê®Æªí¡A±z¥²¶·´£¨ÑÄæ¦ì¦WºÙ©M­È¡C

INSERT INTO Authors (Author, [Year Born]) VALUES ('Frank Whale', 1960)

¦pªG¸ê®Æªí¤¤¦³¥Ñ¸ê®Æ®w¤ÞÀº¦Û°Ê²£¥Íªº¡uÃöÁäÄæ¦ì¡v¡]key field¡^¡Ð´N¹³¬O¦bAuthors¸ê®Æªí¤¤ªºAu_IdÄæ¦ì¡A±z´N¤£­n¦b©R¥O¤¤¥[¤J³o­ÓÄæ¦ì¡ANull­È¬O¦b±z·s¼W¬Ù²¤Äæ¦ì®É¸ê®Æ®w¤ÞÀº¤S¤£¦Û°Ê²£¥Í¸ÓÄæ¦ìªº­È®É©Ò¦Û°Ê±a¶i¥hªº­È¡C¦pªG±z·Q·s¼Wªº¸ê®Æ¤w¸g¦s¦b¥t¤@­Ó¸ê®Æªí¤¤¤F¡A±z¥i¥H¥[¤JSELECT©R¥O¨ìINSERT INTO¥y¤l¤¤¡A¨Ò¦p¡G¤U­±ªº©R¥O¬OCopyNewAuthors¸ê®Æªí©Ò¦³ªº¸ê®Æ¨ìAuthors¸ê®Æªí¡G

INSERT INTO Authors SELECT * FROM NewAuthors

±z¸g±`·|»Ý­n¥Î¨ìWHERE¤l¥y­­¨î­n·s¼Wªº¸ê®Æ¡A±z¥i¥H±q¸ê®Æªícopy¤£¦Pªº¸ê®Æ®wµ²ºc©Î¬O¤£¦PªºÄæ¦ì¦WºÙ¡A¦ý¬O±z»Ý­n¥Î§O¦WÅýÄæ¦ì¦WºÙ¬Û²Å¡C¤U­±ªº¥y¤l±qContact¸ê®Æªícopy¨ìCustomer¸ê®Æªí¦ý¬O­n§ó§ïÄæ¦ì¦WºÙ¡G

INSERT INTO Customers SELECT ContactName AS Name, Address, City, State 
    FROM Contacts WHERE Successful = True

UPDATE©R¥O
¡@

UPDATE©R¥O¬O¥Î¨Ó­×§ï¤@µ§©Î¦hµ§¸ê®Æ¡A±z·|±`±`¨Ï¥ÎWHERE¤l¥y¨Ó¹ï±z­n­×§ïªº¸ê®Æ§@­×§ï¡G

UPDATE Authors SET [Year Born] = 1961 WHERE Author = 'Frank Whale'

±z¤]¥i¥H¥ÎSET¤l¥y¨Ó¨Ï¥Î¹Bºâ¦¡¡A¨Ò¦p¡G¤U­±ªº¥y¤l¼W¥[¦bOrder Details¸ê®Æªí¤¤©Ò¦³¶µ¥Øªº´¿³QLILAS­qÁʪº§é¦©¡C¡]¦bNWind.mdb¸ê®Æ®w¤U°õ¦æ¡^

UPDATE [Order Details] INNER JOIN Orders 
    ON [Order Details].OrderID = Orders.OrderID 
    SET Discount = Discount + 0.10 WHERE CustomerID = 'LILAS'

DELETE©R¥O
¡@

DELETE©R¥OÅý±z¥i¥H±q¸ê®Æªí¤¤§R°£¤@µ§©Î¬O¦hµ§ªº¸ê®Æ¡A±z¥²¶·¥[¤JWHERE¤l¥y¨Ó«ü©w¦b¸ê®Æªí¤¤­n§R°£ªº¸ê®Æ¡C¨Ò¦p¡A¤U­±ªº©R¥O§R°£©Ò¦³¥Xª©¤é´Á¦b1950¦~¤§«eªº®Ñ¡G

DELETE FROM Titles WHERE [Year Published] < 1950

¦pªG¦b¨â­Ó¸ê®Æªí¤§¶¡¦³¨Ï¥ÎÃöÁpªº¸Ü¡A¤@­ÓDELETE¾Þ§@¥i¥HIJµo¨ä¥L¸ê®Æªíªº§R°£§@·~¡A¨Ò¦p¡A±z¥i¥H§R°£¦bNwind.mdb¤¤ªºOrders¸ê®Æªíªº¤@µ§¸ê®Æ¡A¦ÓJet¤ÞÀº·|¦Û°Êªº§R°£©Ò¦³¦bOrder Details¸ê®Æªí¤¤¦³ÃöÁpªº¸ê®Æ¡C¤@¯ë¨Ó»¡¡AµL½×¦p¦ó¡A±z¤£¯à§R°£¤@µ§¦³³Q¨ä¥L¸ê®Æªí°Ñ·ÓªºÁä­È¤¤ªº¸ê®Æ¡A¤]´N¬O¤£¯à§R°£Employees¸ê®Æªí¤¤ªº¸ê®Æ°£«D±z¥ý§R°£¦bOrders¸ê®Æªí¤¤ªºEmployeeIDªº°O¿ý­È¬O«ü¦V±z·Q§R°£ªº°O¿ý¡C±z¥i¥H¨Ï¥Î¤@­ÓINNER JOIN¤l¥y¥[¨ìDELETE©R¥O¤¤¡C½Ð¨c°O¡A·í¦P®É¨Ï¥Î¦h­Ó¸ê®Æªí®É·|Åܱo«Ü½ÆÂø¡A±z¥²¶·¦bDELETE©R¥O¤§«á¸Ô­z±z·Q§R°£ªº°O¿ý¬O­þ¤@­Ó¡G

DELETE Orders.* FROM Orders INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID WHERE Employees.LastName = 'King'

°µ§¹«á±z´N¥i¥H§R°£¦bEmployees¸ê®Æªí¤¤ªº¸Óµ§¸ê®Æ¤F¡G

DELETE FROM Employees WHERE Employees.LastName = 'King'

³o¤@³¹µ²§ô¤F³o¥»®Ñªº²Ä¤@³¡¥÷¡A¨ä¤¤¥]§t¤F¦b±zÆp¬ã§ó½ÆÂøªºµ{¦¡¶}µo¼¶¼g®É©Ò»Ýªº©Ò¦³°ò¥»·§©À¡A§Ú­Ì±N¦b ²Ä13³¹ ¨ÓÁ¿¸ê®Æ®wµ{¦¡¼¶¼gªº³¡¤À¡A¨ì®É¦A¬Ý¬Ý¦p¦ó±o¨ì¨Ï¥Î¸òÀHµÛVisual Basic©ÒªþªºActiveX±±¨î¶µªº§Q¯q¡C