Download - VB + Oracle Connection by AB Sir
![Page 1: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/1.jpg)
VB6 + Oracle Connection
By Amitav Biswas
(MBA,MCA, B.Sc. (H) in Computer Science)
Teacher/ HOD, Computer Sci. Dept.,Behala College & Vivekananda College
![Page 2: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/2.jpg)
1st Technique(Using Data Form Wizard)
![Page 3: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/3.jpg)
Connect to remote system using ODBC
Logon Windows XP/ Win 7 Select Start > Settings > Control Panel In the Control Panel Window, open
“Administrative Tools - Data Sources (ODBC)”
Click the “User DSN” tab Click the “Add..” Button
![Page 4: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/4.jpg)
In the “Create New Data Source”, select “Microsoft ODBC for Oracle”
In the “Microsoft ODBC for Oracle Setup” dialog, enter the following:Database Source Name: ora8iDescription: <optional>Username: <optional>Server Name: <Optional>
Click OK
![Page 5: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/5.jpg)
Create table under remote system Start “Oracle -> OraHome80 ->
Application Development -> SQL PlusUser Name: ScottPassword: TigerHost String: <Optional>
![Page 6: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/6.jpg)
Creation of Sample Table to Test:
SQL> create table Student (S_ID number(8),StuName varchar2(20),Marks Number(8));
SQL> insert into Student (S_ID, StuName, Marks) values (12345, ‘XYZ’, 85);
![Page 7: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/7.jpg)
SQL> commit;SQL> exit;
![Page 8: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/8.jpg)
Access the remote database under Visual Basic 6 using Data Form Wizard:
Starts Visual Basic 6 Open a new Standard .EXE project
under the new tab From the Add-Ins menu, select Add-In
Manager, double click VB 6 Data Form Wizard and click OK
![Page 9: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/9.jpg)
Under Add-Ins menu, select Data Form Wizard
Click Next on the after finish reading the Introduction screen
Under the Data-Type Screen, choose Remote(ODBC), click Next
Under Connection Information, ODBC Connect Data:
![Page 10: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/10.jpg)
DSN: ora8iUser Name: ScottPassword: Tiger
![Page 11: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/11.jpg)
Single Record Form Layout: 1 Under Form Layout, Name the
form: “Customerform” and check Single record, under Binding Type, select ADO Code, click Next
(For Grid (DataSheet) Form Layout, create another Data Form and select the Grid option after this exercise)
![Page 12: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/12.jpg)
Under Record Source, select Student Click the double arrow to bring all the
available fields of All_Customer_Table to the selected field, click Next
Under Control Selection, make sure all the available controls are checked, and click Next, click Finish
![Page 13: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/13.jpg)
Select Project1 Properties from the Project Menu, under Startup Object, select Customerform and click OK
Run the program (Menu Run—Start or Press F5)
(If any error occur during the run-time mode, just end the application (not VB) and start it again!)
![Page 14: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/14.jpg)
Layout:
![Page 15: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/15.jpg)
To Add a Record: Click the Add Button Type all the information to the fields in
specified format Click the Update Button
![Page 16: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/16.jpg)
To Browse the Records: Click the left and right arrow at the
bottom of the form To Delete a Record:
Select the desired record to delete Click the Delete Button Click the Refresh Button to refresh the
table
![Page 17: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/17.jpg)
To Modify a Record: Select the desired record to modify Click the Edit button, modify the data Click the Update Button
Click Close to quit
![Page 18: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/18.jpg)
Note..!! In the design mode, double click on the items
(buttons, labels, textboxes) and investigate the corresponding code
(Especially code in the following procedures: Form_Load, adoPrimaryRS_MoveComplete, cmdAdd_Click, cmdDelete_Click, cmdRefresh_Click, cmdEdit_Click, cmdUpdate_Click, cmdNext_Click, SetButtons)
Repeat the above steps using the Grid (DataSheet) Form Layout
![Page 19: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/19.jpg)
2nd Technique(Using Coding)
[Connecting to- Oracle Using ADO Object]
![Page 20: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/20.jpg)
Know it First.!! ADO –ActiveX data Object OLEDB- Object Linking and
Embedding, Database ADODC- ActiveX data object database
control ADODB- ActiveX Data Objects for Data
Base
![Page 21: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/21.jpg)
Adding References..
![Page 22: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/22.jpg)
![Page 23: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/23.jpg)
![Page 24: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/24.jpg)
Adding Components..
![Page 25: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/25.jpg)
![Page 26: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/26.jpg)
![Page 27: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/27.jpg)
After Adding Component..
![Page 28: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/28.jpg)
Form Layout Design
![Page 29: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/29.jpg)
Adding Module..
![Page 30: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/30.jpg)
Code for Module:Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset
![Page 31: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/31.jpg)
Coding for “Save” Button:
Private Sub Command1_Click()If rs.State = 1 Then rs.Closers.CursorLocation = adUseClientcn.Open "Provider = msdaora.1;user id=scott;password=tiger"rs.Open "select * from Stu", cn, adOpenStatic, adLockBatchOptimistic
![Page 32: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/32.jpg)
Continuation..rs.AddNewrs(0) = Text1.Textrs(1) = Text2.Textrs.UpdateBatchMsgBox "New Student was added Successfully..!!", vbInformation, "Process Completed"
End Sub
![Page 33: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/33.jpg)
Coding for “Clear” Button:
Private Sub Command2_Click()Text1.Text = " "Text2.Text = " "
End Sub
![Page 34: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/34.jpg)
Coding for “Exit” Button:
Private Sub Command3_Click()Unload Me
End Sub
![Page 35: VB + Oracle Connection by AB Sir](https://reader033.vdocuments.us/reader033/viewer/2022042706/577cc1771a28aba711932840/html5/thumbnails/35.jpg)
Sample Output: