Legal | Privacy
<OBE Template> Building .NET Applications Using Oracle Developer Tools For Visual Studio .NET

Building .NET Applications Using Oracle Developer Tools For Visual Studio .NET

This module describes how you can build .NET applications using Oracle Developer Tools for Visual Studio .NET.

30 minutes

This module will discuss the following topics:

Place your mouse on this icon to load and view all the screenshots for this tutorial. (Caution: Because this action loads all screenshots simultaneously, response time may be slow depending on your Internet connection.)

Note: Alternatively, you can place the cursor over each individual icon in the following steps to load and view only the screenshot associated with that step.

The new Oracle Developer Tools for Visual Studio .NET is a tightly integrated "Add-in" for Visual Studio .NET that brings the power of the Oracle Database to .NET developers! Designed to be completely intuitive for database developers, your productivity will increase starting on day one. And if you are new to Oracle development, this is an easy way to learn!

Use the Oracle Explorer to browse your Oracle schema, launch one of the many powerful designers and wizards to create and alter schema objects, and drag and drop schema objects onto your form to automatically generate code.

There's also a PL/SQL editor, Adhoc SQL Query Window, and integrated context sensitive online help, including the Oracle SQL and PL/SQL Users Guides. And with the Oracle Data Window you won't have to leave the Visual Studio environment for routine database tasks like inserting and updating Oracle data or testing stored procedures!

This and many other features greatly improve developer productivity and make developing for Oracle on Windows easy to learn!

Perform the following steps:

1.

Verify you can connect to database which is 8.1.7.4.1 or later

 

2.

Install Oracle Developer Tools ( http://otn.oracle.com/dotnet ) into a new Oracle Database 10g Oracle Home. You should not install into a Oracle8 or Oracle9 Oracle Home. By default it will choose to create a new Oracle home. If you have previously only used Oracle8 or Oracle9 Oracle homes, you should copy your tnsnames.ora file (..in Oracle_home/network/admin) over to the new Oracle home so that your connection aliases are still available to you.

 

Before you begin creating your application, you will open Visual Studio and examine the interface. Perform the following steps:

1.

Select Start > Programs > Microsoft Visual Studio .NET > Microsoft Visual Studio .NET.

 

2.

Select View > Oracle Explorer.

 

3.

Click the + icon to add a connection.

 

4.

Enter your Data source name. Enter hr for the User name and Password, click Save password and click Test Connection.

 

5.

Test connection was successful. Click OK.

 

6.

Click OK.

 

7.

Your connection has been created. Expand hr.<database>. In the next topic, you will create a new table.

 

Now you will create a new table called DEPENDENTS which has a foreign key with the EMPLOYEES table.

Create the Columns
Create the Index
Create the Foreign Key

Create the Columns

To create the columns in the table, perform the following:

1.

Right-click on Tables and select New Relational Table...

 

2.

Enter DEPENDENTS for Table Name and click Add in the columns section.

 

3.

Enter FIRSTNAME for the Name, select VARCHAR2 for the Data type and enter 30 for the Size. Then click Add.

 

4.

Enter LASTNAME for the Name, select VARCHAR2 for the Data type and enter 30 for the Size. Then click Add.

 

5.

Enter BIRTHDATE for the Name, and select DATE for the Data type. Then click Add.

 

6.

Enter RELATIONSHIP for the Name, select VARCHAR2 for the Data type and enter 20 for the Size. Then click Add.

 

7.

Enter EMPLOYEEID for the Name, select NUMBER for the Data type and enter 6 for the Precision and 0 for the Scale. Then click Add.

 

8.

Enter DEPENDENTID for the Name, select NUMBER for the Data type and enter 4 for the Precision and 0 for the Scale. Then click Save. Now you are ready to create the index.

 

Back to Topic

Create the Index

To create the index for the table, perform the following:

1.

Click the Indexes tab.

 

2.

Click Add.

 

3.

Enter DEPENDENTS_INDX for the Name and click Add in the Index Keys area.

 

4.

Select DEPENDENTID for the Key and then click Save. Your index has been created.

 

Back to Topic

Create the Foreign Key

To create the foreign key for the table, perform the following:

1.

Click the Constraints tab.

 

2.

Click Add.

 

3.

Enter EMPLOYEES_FK for the Name, select Foreign Key for the type, select EMPLOYEES for the table, and select the constraint EMP_EMP_ID_PK. Select EMPLOYEE_ID as the Referenced Column and EMPLOYEEID as the local column. Then click Save.

 

4.

In the Oracle Explorer view, you can see the table, its index and constraint.

 

Back to Topic

You can access the data in a table by performing the following

1.

Right-click on the DEPENDENTS table and select Retrieve Data...

 

2.

Enter at least 4 lines of data. Make sure you enter a valid Employee ID. Then click Save.

 

Back to Topic List

In this topic, you will create a project, and generate the code to show the data in the DEPENDENTS table. Perform the following steps:

1.

From the Start tab, click New Project...

 

2.

Select the Project Type Visual C# Projects, select the Template Windows Application, enter obe1 in the name and specify a valid location. Then click OK.

 

3.

Select the DEPENDENTS table in the Oracle Explorer window and drag and drop it into the Form1 on the right side.

 

4.

Click Yes to save the connection password in the code that is generated.

 

5.

The icons you now see just below your form represent code that has now been automatically generated for you. Specifically an OracleDataAdapter class has been generated which is part of the Oracle Data Provider for .NET. Double click on dependentsOracleDataAdapter1 to view the code.

 

6.

The form will appear with the code that was generated. Expand Windows Form Designer generated code.

 

7.

The OracleDataAdapter is based on the ADO DataAdapter which is designed to make it easy to send data to and from your database and widgets on your form, with a minimal amount of code. The OracleDataAdapter class is provided by the Oracle Data Provider for .NET which was installed when you installed the Oracle Developer Tools. Click the Form1.cs (Design) tab.

 

8.

In order to be able to display the data in the Dependents table in your application, you need to add a DataGrid to the form which is located in the Toolbox. Select View then Toolbox.

 

9.

Select DataGrid from the list of Windows Forms and drag and drop it on your Form1.

 

10.

Double-click on the Datagrid to view the form with code that was generated.

 

11.

Select DataGrid1 from the list of Members.

 

12.

Enter the following code after the InitializeComponent(); Then select Build > Build Solution.

DataSet ds= new DataSet();
dependentsOracleDataAdapter1.Fill(ds);
dataGrid1.DataSource = ds.Tables[0];

Note: If you create a Visual Basic Project, the code for the Public Sub New() method, underneath InitializeComponent() will be as follows:

Dim ds As DataSet = New DataSet
dependentsOracleDataAdapter1.Fill(ds)
DataGrid1.DataSource = ds.Tables(0) 

 

13.

Check your output area to make sure you didn't receive any errors. Then select Debug > Start.

 

14.

Your application runs and a form appears and your data has been populated.

 

Back to Topic List

Now you will create a stored procedure and run it.

Create a Stored Procedure
Edit the Package Body
Run the Stored Procedure

Create a Stored Procedure

1.

From the Oracle Explorer window, right click on Packages and select New Package.

 

2.

Enter MYPACK for the Package name and click Add under Methods.

 

3.

Enter GETCURSORS for the method name, select Procedure for the method type and click Add under Parameters.

 

4.

Enter MAXROWS for the Name and click Add.

 

5.

Enter EMPLOYEESCUR for the Name, select OUT for Direction, and select SYS_REFCURSOR for Data type. Then click Add.

 

6.

Enter DEPENDENTSCUR for the Name, select OUT for the Direction and select SYS_REFCURSOR for the Data type. Then click OK.

 

7.

Click Preview SQL >> to see the SQL that will be executed.

 

8.

Review the SQL and click OK.

 

9.

Click OK to create the Package.

 

Back to Topic

Edit the Package Body

1.

From the Oracle Explorer window, right click on the MYPACK Package you just created and select Edit Package Body.

 

2.

Replace the line NULL; with the following, then right click on the window tab and select Save.

OPEN EMPLOYEESCUR FOR SELECT * FROM EMPLOYEES;
OPEN DEPENDENTSCUR FOR SELECT * FROM DEPENDENTS;

 

Back to Topic

Run the Stored Procedure

1.

Expand the Package MYPACK in the Oracle Explorer window. Right-click on GETCURSORS and select Run.

 

2.

Enter 999 for the MAXROWS parameter value and click OK.

 

3.

Select the value for EMPLOYEESCUR.

 

4.

The details for the Employees cursor are shown. Select the value for the DEPENDENTSCUR.

 

5.

The Dependents cursor details are shown.

 

Back to Topic

In this lesson, you learned how to:

Back to Topic List

Move your mouse over this icon to hide all screenshot

 

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy