VB6 to access Oracle with Oracle Data Controls (transferred from the sky)

xiaoxiao2021-03-06  40

[Documentation] After installed Oracle, there will be ORADC.OCX files in D: / Oracle / ORA81 / BIN / directory, VB can use this control to access the Oracle database

[text]

System environment: 1, operating system: Windows 2000 Server 2, Database: Oracle 8i R2 (8.1.6) For NT Enterprise Edition 3, Development Tools: Visual Basic 6.0 Chinese Connection Method: First, Install Oracle 8i R2 (8.1.6 ) for NT Enterprise Edition typically installs, the installation directory is D: / Oracle; Note: After installed Oracle, there will be ORADC.OCX files in D: / Oracle / ORA81 / BIN / directory, VB can use this control to access Oracle Database 2, Installing the Visual Basic 6.0 Chinese version puts the Visual Basic 6.0 CD into the CD-ROM drive, using a typical installation, installation directory is d: / program files / microsoft Visual Studio / VB98; Log in to SQL> Conn System / Manager with System / Manager User: If User1 / Pass1 gives Connect, Resource Permissions.

SQL> Grant Connect, Resource To User1 Identified by Pass1; SQL> Conn User1 / Pass1 SQL> Create Table Test (A Number, B CHAR (19)); SQL> Insert Into Test Values ​​(1, To_Char (Sysdate, 'YYYY- MM-DD HH24: MI: SS ')); SQL> INSERT INTO TEST VALUES (2, To_Char (Sysdate,' YYYY-MM-DD HH24: MI: SS ')); SQL> Insert Into Test Values ​​(3, TO_CHAR (Sysdate, 'YYYY-MM-DD HH24: MI: SS'); SQL> Insert Into Test Values ​​(4, TO_CHAR (Sysdate, 'YYYY-MM-DD HH24: MI: SS')); SQL> Insert Into Test Values ​​(5, To_CHAR (Sysdate, 'YYYY-MM-DD HH24: MI: SS')); SQL> Commit; SQL> Select * from test; AB ---------- ---- --------------- 1 2000-11-28 20:27:33 2 2000-11-28 20:27:36 3 2000-11-28 20:27:38 4 2000 -11-28 20:27:40 5 2000-11-28 20:27:52 D: /Oracle/ora81/neetwork/admin/tnsnames.ora has the following: ORADB = (description = (address_list = (Protocol = tcp) (host = 192.1.1.1))))) Summary: ORADB ORACE User Name: ORADB ORACLE User Name: User 1 house name Password: Pass1 test table name: test tnsnames: ORADB four, launch Visual Basic 6.0, write to Oracle's VB program start -> Program -> Microsoft Visual Basic 6.0 Chinese version -> Microsoft Visual Basic 6.0 Chinese Document -> New Projects -> VB Enterprise Edition control, as shown below: Add access to Oracle parts (Ctrl T): Engineering -> Components -> Oracle Data Control, as shown below:

Check this control (Oracle Data Control), click OK (this control is the D: /oracle/ora81/bin/undc.oc.oc.oc.ocx) VB The Toolbox panel on the right side of the VB will appear on the toolbox panel on the right side. As shown below:

Use the mouse to double-click this control (ORADC), then double-click the MSFlexGrid control (another drawn red box above), put them on the form FORM1, the default name is ORADC1 and MSFLEXGRID1, as shown below: Modify the control ORADC1 and MSFLEXGRID1 Attribute, as shown below:

ORADC1 CONNECT Properties: User1 / Pass1 ORADC1 DatabaseName Properties: ORADB ORADC1 RecordSource Properties: Select * from test MsflexGrid1 DataSource Property: ORADC1 can also do any properties of ORADC1 control, and use the form's form_load () process to give ORADC1 control assignment private sub form_load () oradc1.connect = "user1 / pass1" oradc1.databaseName = "ORADB" oradc1.recordsource = "select * from test" ORADC1.REfresh End Sub Press F5, run this program, the result is as follows:

转载请注明原文地址:https://www.9cbs.com/read-62911.html

New Post(0)