Anda di halaman 1dari 14

CREATING DATABASE APPLICATION WITH ORACLE & VISUAL BASIC

STEP 1: Create a Table Emp


SQL> desc emp;
Name
Null? Type
----------------------------------------- -------- ----------------EMPNO
ENAME
JOB
MGR
DEPTNO
SALARY

NUMBER(6)
NOT NULL VARCHAR2(20)
VARCHAR2(20)
NUMBER(4)
NUMBER(3)
NUMBER(7,2)

STEP2: Design a Form Employee

STEP 3
Accessing Database using ADODC.
In this section we will learn to use the Remote Data Access Object that is the ADO DC data
object. We will illustrate using the control to connect to a Oracle Database and some Demo
tables on the Scott user in Oracle Dbase.
Setting up the ADO Control.
1. Open Visual Basic, start a new project.
2. On the menu tab of Project. Click Components (CTRL+T) .
3. Now add the control >Microsoft ADO Data Control (OLEDB)<

Add an ADO Data Control to the form using the ADODC tool [
Now right click on the ADO control and select ADODC Properties.

Now it will invoke the Property Pages for the ADO DC control that you added. Select the option
use Connection String and then click at the Build button.

Connection to a database.
Now a another dialog Data Link Properties pops up. Select Microsoft OLE DB provider
for Oracle from that list that appears and click on the Next Button.

Now if you are on a single system you dont have to Enter the Server name in the entry field.
Just enter the demo Username :Scott and password: tiger.

after this press the button test connection . If the username and password is valid, then a
message box will appear.

tip : check the allow saving password, otherwise on every run time start, it will ask for a
password.
After this, press Ok in the main dialog box.
Once again in the Property Pages, Click on the RecordSource Tab. Select Command Type from
the drop down box.

Now from the drop down list of Table or Stored Procedure Name drop down box, select the
Table EMP

Few Notes on Command Type methods


-adcmdText
The Source string contains a SQL command, such as a select statement.
-adCmdTable
The Source string contains the name of a table to be retrieved. (ADO itself creates the
query without the user seeing it). Using this option is not suited for large tables as it
contains all the records, and thus handling may become cumbersome. Use it only for
small tables like the EMP table of Scott User.
-adCmdStoredProc
The Source string contains the name of a stored procedure (not applicable to Oracle.)
-adCmdUnknown.
This constant indicates that the type of command in the Source argument is not known.
Using this option is inefficient.

STEP 4
Select the text control and change the properties as:
Data Source : Adodc1
Date Field : EmpNo
Like assign all text field with adodc for connect data source to text controls.

STEP 5
Add the command controls such as ADDNEW, SAVE, DELETE, UPDATE
Write the Event coding by click

Private Sub Command1_Click()


Adodc1.Recordset.AddNew
End Sub
Private Sub Command2_Click()
Adodc1.Recordset.Delete
MsgBox "Record Deleted"
End Sub
Private Sub Command3_Click()
Adodc1.Recordset.Update
End Sub
Private Sub Command4_Click()
Adodc1.Recordset.Save
End Sub

STEP 6
Add the command controls such as MOVE FIRST, MOVE NEXT, MOVE PREVIOUS AND MOV
LAST
Write the Event coding by click

Private Sub Command5_Click()


Adodc1.Recordset.MoveFirst
End Sub
Private Sub Command6_Click()
Adodc1.Recordset.MoveNext
End Sub
Private Sub Command7_Click()
Adodc1.Recordset.MovePrevious
End Sub
Private Sub Command8_Click()
Adodc1.Recordset.MoveLast
End Sub

STEP 7
Run you project by F5

REPORT GENERATION
STEP 1: ADDING DATA REPORT
Start Visual Basic as a Standard EXE project. From the Project menu in the VBE, select Add Data Report
in the dropdown menu. Now, you will be presented with the data report environment, as shown in Figure
The data report environment contains six controls, they are RptTextBox, RptLine, RptFunction,
RptLabel, RptImage and RptShape.
You can customize your report here by adding a title to the page header using the report label RptLabel.
Simply drag and draw the RptLabel control on the data report designer window and use the Caption
property to change the text that should be displayed. You can also add graphics to the report using the
RptImage control.

STEP 2: CONNECTING THE REPORT TO DATABASE USING


DESIGNER

DATA ENVIRONMENT

Click the Project menu, then select Data Environment. from the drop-down menu. The default data
environment will appear, as shown in figure

Select the Connection1 -> Properties

Select Provider -> Microsoft OLE DB Provider for Oracle


Click Next.

Select the Connection. Enter Server Name, UserName & Password.


Also Choose Allow Saving Password & Press Ok Button.

Step 3: Retrieving Information from the Database


In order to use the database in your report, you need to create query to retrieve the information from the database.
Here , we will use SQL command to create the query. First of all, right click on MyConnection to add a command to
the data environment.

Select Command1 - > Properties

Choose Source of Data


o Database Object as Table
o Object Name as EMP (Table Name)

Expand the Command1 Button to Choose all the fields.


To add data to your report, you need to drag the fields from MyCommand in
MyDataEnvironment into MyDataReport, as shown in Figure

Choose the DataReport1 and set the


o DataSource as DataEnvironment1
o DataMember as Command1.

STEP 4: Run the Report.

Anda mungkin juga menyukai