¡@

¡@

¡@

¡@ ¡@ ¡@
10-1 ¬ÛÃö¨t²Î³]©w»P¤u¨ãªºÀ³¥Î 10-2À³¥Î³nÊ^¶}µo¤u¨ã Visual Basic  
10-3 À³¥Î³nÊ^¶}µo¤u¨ã Delphi ¡@ ¡@
¡@ ¡@
¡@

Oracle ¥»¨­¬°¦øªAºÝ(Server) ªº¸ê®Æ®w¨t²Î¡A¥²¶·»P¨Ï¥ÎªÌºÝ(Client) ªºÀ³¥Î³nÊ^¶}µo¤u¨ãµ²¦X¡A¤~¯àµo´§¨ä±j¤jªº¸ê®Æ®w¯à¤O¡A¥Ø«e¥«³õ¤W³Ì±`¥ÎªºÀ³¥Î³nÊ^¶}µo¤u¨ã¡A¨Ò¦p¡GVB¡ADelphi¡APowerBuilder »P Oracle ªº Form¡CVisual Basic ¬O Microsoft ¤½¥q¥X«~¡A«D±`¾A¦X¶}µo¦UºØ¨t²Î¡A¨ä¤¤¤]¥]¬A Oracle «eºÝªºÀ³¥Î³nÊ^¡C°²³]¥D¾÷¦r¦ê³]©w¬° jp8i¡C³s½u¤èªk¦³¨Ï¥Î ODBC¡B¨Ï¥Î Oracle Data Control »P Microsoft ADO Data Control¡C³oùاڭ̤¶²Ð³Ì«á¤@ºØ¤èªk¡C
¡@

°õ¦æVB «Øij¶}©l¥ø·~ª©±±¨î¶µ¡AµM«áÂI¿ï¶}±ÒÂÂÀÉ¡A¦p¹Ï©Ò¥Ü¡C

¦b VB ±±¨î¶µ¤¤¡A¿ï©w Adodc ¤¸¥ó¡AµM«á©ì¦²¦Üªí³æ¤¤²£¥Í Adodc ±±¨î¶µ¡A¨Ò¦p¡GAdodc1¡C

¦b Adodc ±±¨î¶µ¤W«ö¥kÁä¨ÃÂI¿ï ADODC ªºÄÝ©Ê¡AµM«á¦b¡§¤@¯ë¡¨­¶ÅÒ¤¤ÂI¿ï¡§«Ø¥ß¡¨¡C

¦b¡§´£¨ÑªÌ¡¨­¶ÅÒªº OLE DB Provider ¤¤ÂI¿ï¡§Microsoft OLE DB Provider for Oracle¡¨¨Ã«ö¡§¤U¤@¨B¡¨¡C

°²³]¨Æ«e¤w§Q¥Î Net8 Easy Config ³]©w¦n¤F¦øªA¾¹ JP8i¡C¦b¡§³s±µ¡¨­¶ÅÒ¤¤Áä¤J¦øªA¾¹ªº¦WºÙ¡A¨Ò¦p¡GJP8i¡A¨Ã¿é¤J¨Ï¥ÎªÌ¦WºÙ»P±K½X¡A¨Ò¦p¡Gscott¡A¨Ã°O±oÂI¿ï¡§¤¹³\Àx¦s±K½X¡¨¡A³]©w¦n¤F´NÂI¿ï¡§´ú¸Õ³s±µ¡¨¡A¬Ý¬O§_¥i¥H³s½u¡A¦pªG³s½u¦¨¥\¡A«h¨t²Î·|¦^ÂС§´ú¸Õ³s±µ¦¨¥\¡¨¡AµM«á«ö¡§½T©w¡¨Â÷¶}¡C

ÂI¿ï¡§¸ê®Æ¿ý¨Ó·½¡¨­¶ÅÒ¡A¨ä¤¤©R¥OÃþ«¬¥i¤À¬° (1) adCmdText¡G¸ê®Æ¿ý¨Ó·½¬O¥Ñ°õ¦æ SQL «ü¥O©Ò²£¥Í¡A(2) adCmdTable¡G¸ê®Æ¿ý¨Ó·½¬O¤@¯ëªºªí®æ¡A(3) adCmdStoredProc¡G¸ê®Æ¿ý¨Ó·½¬O Stored Procedure¡A(4) ¸ê®Æ¿ý¨Ó·½¬O¨ä¥Lªº®æ¦¡ÀɮסC§Ú­Ì¥H adCmdText »P adCmdTable °µ¬°¨Ò¤l»¡©ú¡C

¡uadCmdText¡v¨Ò¤l¡Gªí¥Ü¸ê®Æ¨Ó·½¬° SQL ¬d¸ßµ²ªG¡C¥ý¦b©R¥OÃþ«¬¤¤ÂI¿ï adCmdText ¨Ã¥B¦b©R¥O¤å¦r¤¤Áä¤J SQL «ü¥O¡AµM«á«ö¡§½T©w¡¨§Y¥i¡C

¡uadCmdTable¡v¨Ò¤l¡Gªí¥Ü¸ê®Æ¨Ó·½¬°¸ê®Æ®w¤¤ªºªí®æ¡C¥ý¦b©R¥OÃþ«¬¤¤ÂI¿ï adCmdTable ¨Ã¥B¦b¸ê®Æªí¤¤ÂI¿ïªí®æ¡A¨Ò¦p¡GEMP¡AµM«á«ö¡§½T©w¡¨§Y¥i¡C

¦Ü¥Ø«e¬°¤î¡A§Ú­Ì¤w§¹¦¨¤Fªí³æ»P Oracle ¥D¾÷³s½uªº³]©w¡C

¡@ ¡@

VB ´£¨Ñ³\¦hData Aware ¤¸¥ó¨ÓÅã¥Ü¸ê®Æ®w¤¤ªº¸ê®Æ¡A¨Ò¦p¡GText Box¡AData Grid¡AData Combo¡AData list µ¥µ¥¤¸¥ó¡A³o³¹¸`§Ú­Ì¤¶²Ð Data Grid ¡C
¡@

¦b VB ±±¨î¶µ¤¤¡AÂI¿ï¡§DataGrid¡¨¤¸¥ó¡AµM«á©ì¦²¦Üªí³æ¤¤²£¥Í DataGrid ±±¨î¶µ¡A¨Ò¦p¡GDataGrid1¡A¨Ã¦b¨äÄݩʤ¤ªº DataSource Äæ¦ì (¸ê®Æ¨Ó·½) ¤¤ÂI¿ï Adodc1¡C

ÂI¿ï«ö¶s¤¸¥ó«Ø¥ß°O¿ý¾Þ±±±±¶s¡A¨Ò¦p¡G²Ä¤@µ§¡B¦V¤W¤@µ§¡B¦V¤U¤@µ§¡B³Ì«á¤@µ§¡B·j´M¡Bµ²§ô¡C¡i²Ä¤@µ§¡j¡B¡i¦V¤W¤@µ§¡j¡B¡i¦V¤U¤@µ§¡j¡B¡i³Ì«á¤@µ§¡j¥|ºØ¾Þ±±«ö¶sµ{¦¡¦p¤U¡G

µM«á°õ¦æ¡C

¡@ ¡@

Private Sub Command11_Click(Index As Integer)
  Const MOVE_FIRST = 0 '³Ì«e
  Const MOVE_PREVIOUS = 1 '¤W¤@µ§
  Const MOVE_NEXT = 2 '¤U¤@µ§
  Const MOVE_LAST = 3 '³Ì«á
  Select Case Index
  Case MOVE_FIRST '²¾¦Ü³Ì«e
  Adodc1.Recordset.MoveFirst
  Case MOVE_PREVIOUS '²¾¦Ü¤W¤@µ§
  Adodc1.Recordset.MovePrevious
  If Adodc1.Recordset.BOF Then '¬O§_¹LÀY
     Adodc1.Recordset.MoveFirst '²¾¦Ü³Ì«e
     Beep 'ĵ§iÁn
     MsgBox "³o¤w¬O²Ä¤@µ§¸ê®Æ", vbOKOnly + vbExclamation, ""
     Exit Sub
  End If
  Case MOVE_NEXT '²¾¦Ü¤U¤@µ§
  Adodc1.Recordset.MoveNext
  If Adodc1.Recordset.EOF Then '¬O§_¦Ü§ÀºÝ
     Adodc1.Recordset.MoveLast '²¾¦Ü³Ì«á
     Beep 'ĵ§iÁn
     MsgBox "³o¤w¬O³Ì«á¤@µ§¸ê®Æ", vbOKOnly + vbExclamation, ""
     Exit Sub
  End If
  Case MOVE_LAST '²¾¦Ü³Ì«á
  Adodc1.Recordset.MoveLast
  End Select
End Sub

¡@ ¡@
¡i·j´M¡j«ö¶sµ{¦¡¦p¤U¡G ¡@

Private Sub Command3_Click()
Dim num As String
Dim pos As Variant
num = InputBox("½Ð¿é¤J­û¤u½s¸¹", "·j´M­û¤u½s¸¹", "1")
If num <> "" Then '¦³¿é¤J¸ê®Æ
  pos = Adodc1.Recordset.Bookmark '°O¿ý¥Ø«e¸ê®Æ«ü¼Ð¦ì¸m
  num = "empno=" & "'" & num & "'" '·j´M¦r¦ê
  Adodc1.Recordset.MoveFirst
  Adodc1.Recordset.Find (num) '·j´M
  If Adodc1.Recordset.EOF Then '§ä¤£¨ì
    MsgBox "¥Ø«e¨S¦³³o­Ó½s¸¹ªº­û¤u¸ê®Æ", vbOKOnly + vbExclamation, ""
    Adodc1.Recordset.Bookmark = pos '¦^¦s­ì¥ý¸ê®Æ«ü¼Ð¦ì¸m
  End If
End If
End Sub

¡@
¡iµ²§ô¡j«ö¶sµ{¦¡¦p¤U¡G

Private Sub Command2_Click()
 End
End Sub

¡@

VB ´£¨Ñ³\¦hData Aware ¤¸¥ó¨ÓÅã¥Ü¸ê®Æ®w¤¤ªº¸ê®Æ¡A¨Ò¦p¡GText Box¡AData Grid¡AData Combo¡AData list µ¥µ¥¤¸¥ó¡A³o³¹¸`§Ú­Ì¤¶²Ð TextBox ¡C
¡@

¦b VB ±±¨î¶µ¤¤¡AÂI¿ï¡§TextBox¡¨¤¸¥ó¡AµM«á©ì¦²¦Üªí³æ¤¤²£¥Í TextBox ±±¨î¶µ¡A¨Ò¦p¡GText1¡A¨Ã¥ý¦b¨äÄݩʤ¤ªº DataSource Äæ¦ì(¸ê®Æ¨Ó·½) ¤¤ÂI¿ï Adodc1¡AµM«á¦bÄݩʤ¤ªº DataField ¿ï¾Üªí®æ¤¤ªº¬Y­ÓÄæ¦ì¡A¦p¦¹´N«Ø¥ß¤F¤@­ÓÄæ¦ìªºÅã¥Ü¡C

­«ÂÐ «Ø¥ß¨ä¥LÄæ¦ìªºÅã¥Ü¡A¨Ã¥B¥i§Q¥Î VB ±±¨î¶µ¤¤ªº¡§Lebel¡¨¤¸¥ó«Ø¥ß¨C­ÓÄæ¦ìªº¼ÐÃD¡C

ÂI¿ï«ö¶s¤¸¥ó¨Ã¦p¦P«eªº¤èªk«Ø¥ß°O¿ý¾Þ±±«ö¶s¡A¨Ò¦p¡G²Ä¤@µ§¡B¦V¤W¤@µ§¡B¦V¤U¤@µ§¡B³Ì«á¤@µ§¡B·j´M¡Bµ²§ô¡C

µM«á°õ¦æªí³æ¡C

¡@ ¡@

©Ò¿× Master-detail ÃöÁp¬[ºcªí³æ§Y¬O¤Ï¬M¨â­Ó¸ê®Æ°Ï¶ô(block) ©Ò¹ïÀ³¤§°ò¥»ªí®æ¤§¶¡ªºÃöÁp¡CMaster block ¬°¹ïÀ³¾Ö¦³³QÃöÁp¥DÁ䪺°ò¥»ªí®æ¤§¸ê®Æ°Ï¶ô¡A¦Ó Detail block ¬°¹ïÀ³¾Ö¦³¥~¨ÓÁ䪺°ò¥»ªí®æ¤§¸ê®Æ°Ï¶ô¡CMaster-detail ÃöÁp¬[ºcªí³æ¤Ï¬M¨â­Ó°ò¥»ªí®æ¤§¶¡ªº¤@¹ï¦hÃö«Y¡C§Q¥Î VB ¦s¨ú¸ê®Æ®wªº­º­n¤§°È¬O«Ø¥ß Recordset ª«¥ó¡AµM¦Ó«Ø¥ß Recordset ª«¥óªº¤èªk«Ü¦h¡A±`¨Ïªì¾ÇªÌ¤£ª¾©Ò±¹¡A¦Ó Data Environmentªº¥D­n¥\¯à¬O§â³o¨Ç¤èªk¾ã¦X°_¨Ó¨Ã´£¨Ñ¸ê®Æ®wµ{¦¡¤@­Pªº¤¶­±¡C
¡@

¦b VB ¤u¨ã¦C¤WÂI¿ï ±M®×¡÷¨ä¥Lªº ActiveX Designer¡÷Data Environment¡A·|¶i¤J Data Environment ³]­pÀô¹Ò¨Ã²£¥Í¤F Connection ¤¸¥ó Connection1¡C

±µ¤U¨Ó§Ú­Ì­n³]©w»P Oracle ªº³s½u¡A¦b Data Environment ¤Uªº Connection ¤¸¥ó Connection1 ¤W«ö¥kÁä¨Ã¿ï¾Ü¡§ÄÝ©Ê¡¨«á¡A·|¥X²{³]©w¸ê®Æ³s±µªºµøµ¡¡A¦b¡§´£¨ÑªÌ¡¨­¶ÅÒ¤WÂI¿ï¡§Microsoft OLE DB Provider for Oracle¡¨¨ÃÂI¿ï¡§¤U¤@¨B¡¨¡C

¦b¡§³s±µ¡¨­¶ÅÒ¤¤Áä¤J¦øªA¾¹ªº¦WºÙ¡A¨Ò¦p¡Gjp8i¡A¨Ã¿é¤J¨Ï¥ÎªÌ¦WºÙ»P±K½X¡A¨Ò¦p¡Gscott¡A¨Ã°O±oÂI¿ï¡§¤¹³\Àx¦s±K½X¡¨¡A³]©w¦n¤F´NÂI¿ï¡§´ú¸Õ³s±µ¡¨¡A¬Ý¬O§_¥i¥H³s½u¡A¦pªG³s½u¦¨¥\¡A«h¨t²Î·|¦^ÂС§´ú¸Õ³s±µ¦¨¥\¡¨¡AµM«á«ö¡§½T©w¡¨Â÷¶}¡C

¦b Data Environment ¤Uªº Connection ¤¸¥ó Connection1 ¤W«ö¥kÁä¨Ã¿ï¾Ü¡§·s¼W«ü¥O¡¨¡A§Y¥i²£¥Í Command ¤¸¥ó Command1¡C

¦b Command ¤¸¥ó Command1 ¤W«ö¥kÁä¨ÃÂI¿ï¡§ÄÝ©Ê¡¨¡A¥X²{ Command1 ¤º®eªºµøµ¡¡A¦b¡§¤@¯ë¡¨­¶ÅÒ¤§¸ê®Æ¨Ó·½¤¤ªº¸ê®Æ®wª«¥ó¤§ºØÃþ»P¥ý«e¤¶²Ðªº Adodc ¤¸¥óÃþ¦ü¡A©Ò¥H³o¸Ì§@ªÌ¤£¦A­«ÂСC³o¸Ì¥H¸ê®Æªí¬°¨Ò¡A¦bª«¥ó¦WºÙ¤¤Áä¤J SCOTT.DEPT¡AµM«áÂI¿ï¡§½T©w¡¨¡C

¦b Command ¤¸¥ó Command1 ¤W«ö¥kÁä¨ÃÂI¿ï¡§·s¼W¤l«ü¥O¡¨¡A§Y¥i¦b Command1 ¤U²£¥Í¤@­Ó·sªº Command ¤¸¥ó Command2¡C

¦b Command ¤¸¥ó Command2 ¤W«ö¥kÁä¨ÃÂI¿ï¡§ÄÝ©Ê¡¨¡A§Y¥i¥X²{ Command2 ¤º®eªºµøµ¡¡A¦b¡§¤@¯ë¡¨­¶ÅÒªº¸ê®Æ¨Ó·½¤¤¤§¸ê®Æ®wª«¥ó¤¤ÂI¿ï¸ê®Æªí¡A¨Ã¦bª«¥ó¦WºÙ¤¤Áä¤J SCOTT.EMP¡C

°²¦p¨â­Óªí®æ¶¡¦³³]©w¦n°Ñ¦Ò¾ã¦X­­¨î¡A«h¦b¡§ÃöÁp¡¨­¶ÅÒ¤¤ªºÃöÁp©w¸q·|¦Û°Ê¿ï©w¡A¥u­nÂI¿ï¡§·s¼W¡¨±NÃöÁp¥[¤J Command2 ¤¤¡A³]©w¦n«áÂI¿ï¡§½T©w¡¨§Y¥i¡C

³]©w¦nªº Data Environment ¡C

ÂI¿ï Data Environment ¤¤ªº Command1 ¨Ã±N¤§©ì¦²¦Üªí³æ¤W¡C

VB ·|¦Û°Ê¦a²£¥Í¨â­Óªí®æªº Master-detail ªºªí³æ¡C

ÂI¿ï«ö¶s¤¸¥ó«Ø¥ß°O¿ý¾Þ±±±±¶s¡A¨Ò¦p¡G²Ä¤@µ§¡B¦V¤W¤@µ§¡B¦V¤U¤@µ§¡B³Ì«á¤@µ§¡B·j´M¡Bµ²§ô¡C¦p¤U»¡©ú

µM«á°õ¦æ¡A°õ¦æµ²ªG¡C

¡@
¡i²Ä¤@µ§¡j«ö¶sµ{¦¡¦p¤U¡G

Private Sub Command1_Click()
 DataEnvironment1.rsCommand1.MoveFirst
End Sub

¡@
¡i¦V¤W¤@µ§¡j«ö¶sµ{¦¡¦p¤U¡G

Private Sub Command2_Click()
 DataEnvironment1.rsCommand1.MovePrevious
 If DataEnvironment1.rsCommand1.BOF Then
     DataEnvironment1.rsCommand1.MoveFirst
 End If
End Sub

¡@
¡i¦V¤U¤@µ§¡j«ö¶sµ{¦¡¦p¤U¡G

Private Sub Command3_Click()
 DataEnvironment1.rsCommand1.MoveNext
 If DataEnvironment1.rsCommand1.EOF Then
    DataEnvironment1.rsCommand1.MoveLast
 End If
End Sub

¡@
¡i³Ì«á¤@µ§¡j«ö¶sµ{¦¡¦p¤U¡G

Private Sub Command4_Click()
 DataEnvironment1.rsCommand1.MoveLast
End Sub

¡@
¡iµ²§ô¡j«ö¶sµ{¦¡¦p¤U¡G

Private Sub Command5_Click()
 End
End Sub

¡@
¡i·j´M¡j«ö¶sµ{¦¡¦p¤U¡G

Private Sub Command6_Click()
Dim num As String
Dim pos As Variant
num = InputBox("½Ð¿é¤J³¡ªù¥N½X", "·j´M³¡ªù¥N½X", "1")
If num <> "" Then '¦³¿é¤J¸ê®Æ
   pos = DataEnvironment1.rsCommand1.Bookmark '°O¿ý¥Ø«e¸ê®Æ«ü¼Ð¦ì¸m
   num = "deptno=" & "'" & num & "'" '·j´M¦r¦ê
   DataEnvironment1.rsCommand1.MoveFirst
   DataEnvironment1.rsCommand1.Find (num) '·j´M
   If DataEnvironment1.rsCommand1.EOF Then '§ä¤£¨ì
   MsgBox "¥Ø«e¨S¦³³o­Ó½s¸¹ªº³¡ªù¸ê®Æ", vbOKOnly + vbExclamation, ""
   DataEnvironment1.rsCommand1.Bookmark = pos '¦^¦s­ì¥ý¸ê®Æ«ü¼Ð¦ì¸m
   End If
End If
End Sub

¡@

¡@