vb + oracle connection by ab sir

35
VB6 + Oracle Connection By Amitav Biswas (MBA,MCA, B.Sc. (H) in Computer Science) Teacher/ HOD, Computer Sci. Dept., Behala College & Vivekananda College

Upload: amitavbiswas84

Post on 18-Jul-2016

16 views

Category:

Documents


3 download

DESCRIPTION

Visual basic with Oracle connection procedures

TRANSCRIPT

Page 1: VB + Oracle Connection by AB Sir

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

1st Technique(Using Data Form Wizard)

Page 3: VB + Oracle Connection by AB Sir

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

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

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

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

SQL> commit;SQL> exit;

Page 8: VB + Oracle Connection by AB Sir

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

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

DSN: ora8iUser Name: ScottPassword: Tiger

Page 11: VB + Oracle Connection by AB Sir

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

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

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

Layout:

Page 15: VB + Oracle Connection by AB Sir

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

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

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

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

2nd Technique(Using Coding)

[Connecting to- Oracle Using ADO Object]

Page 20: VB + Oracle Connection by AB Sir

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

Adding References..

Page 22: VB + Oracle Connection by AB Sir
Page 23: VB + Oracle Connection by AB Sir
Page 24: VB + Oracle Connection by AB Sir

Adding Components..

Page 25: VB + Oracle Connection by AB Sir
Page 26: VB + Oracle Connection by AB Sir
Page 27: VB + Oracle Connection by AB Sir

After Adding Component..

Page 28: VB + Oracle Connection by AB Sir

Form Layout Design

Page 29: VB + Oracle Connection by AB Sir

Adding Module..

Page 30: VB + Oracle Connection by AB Sir

Code for Module:Public cn As New ADODB.Connection

 Public rs As New ADODB.Recordset

Page 31: VB + Oracle Connection by AB Sir

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

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

Coding for “Clear” Button:

Private Sub Command2_Click()Text1.Text = " "Text2.Text = " "

End Sub

Page 34: VB + Oracle Connection by AB Sir

Coding for “Exit” Button:

Private Sub Command3_Click()Unload Me

End Sub

Page 35: VB + Oracle Connection by AB Sir

Sample Output: