Before You Begin
Purpose
This tutorial describes how you can build ASP.NET web applications that access Oracle Database using Oracle Developer Tools for Visual Studio.Time to Complete
Approximately 30 minutesBackground
Oracle Developer Tools for Visual Studio is a tightly integrated "add-in" for Visual Studio. This tight integration makes it easy to create ASP.NET Web Applications that access Oracle database with minimal coding. This tutorial will guide you how to create such an application.What Do You Need?
Before starting this tutorial, you should:- Install Microsoft Visual Studio 2015 or later.
- Have access to Oracle Database 12c or later.
- Install Oracle Data Access Components (ODAC) 12c Release 4 or later from OTN. Be sure to use the Oracle Universal Installer and include Oracle Developer Tools for Visual Studio as part of the installation. During the install process, choose the machine-wide configuration option.
Creating a Web Site
In this section, you will create a new ASP.NET web site.
-
Open Visual Studio. Click File. Select New > Web Site.
View ImageDescription of this image -
Select Installed > Templates > Visual C# >ASP.NET Web Forms Site. Click OK.
View ImageDescription of this image -
Observe the screen. The project WebSite1 opens up and the Default.aspx file displays on screen.
View ImageDescription of this image
Creating the GridView
In this section, you will create a grid view in the web page. The grid view will display the retrieved Oracle data when the application is run.
-
Click the Design tab in the Default.aspx page.
View ImageDescription of this image -
Select to highlight the text in the MainContent(Custom) region in the Default.aspx page
View ImageDescription of this image -
Delete the selected text by clicking the delete key.
View ImageDescription of this image -
Select Toolbox, from the View menu. The Toolbox appears.
View ImageDescription of this image -
Drag the GridView control under the Data in the Toolbox, to the Default.aspx Design area.
View ImageDescription of this image -
Observe the screen. The design area gets the GridView control.
View ImageDescription of this image
Creating a Data Source
In this section, you will create a new Oracle data source for the grid in the ASP.NET web site. That will allow the grid to retrieve and show Oracle data when the web site is run.
-
Goto Choose Data Source field in the Grid View tasks. Select <New data source...> from the Choose Data Source dropdown.
View ImageDescription of this image -
The Data Source Configuration Wizard opens up. We will retrieve data from the Oracle HR sample schema. Select Database in the Where will the application get data from? field. Enter HR in the Specify an ID for the data source field. Click OK.
View ImageDescription of this image -
The Configure Data Source wizard opens up. Click New Connection... in the Which data connection should your application use to connect to the database? field.
View ImageDescription of this image -
The Add Connection dialog box opens. If Data Source is not already set to Oracle Database (ODP.NET, Managed Driver), click Change...
View ImageDescription of this image -
In the Change Data Source dialog box, select Oracle Database as the Data Source and ODP.NET, Managed Driver as the Data Provider. Click OK. This step is required only if Data Source is not already set to Oracle Database (ODP.NET, Managed Driver).
View ImageDescription of this image -
Enter the following details in the Add Connection dialog box and click OK.
- User name: HR
- Password: HR
- Data source name: ORCL
View ImageDescription of this image -
Connection string configuration is complete. Click Next in the Configure Data Source wizard.
View ImageDescription of this image -
Click Next to save the connection string in the application configuration file.
View ImageDescription of this image -
We will now choose the data to retrieve from the database. In this tutorial, we will select all columns and rows from the EMPLOYEES table. Choose the Specify columns from a table or view option. Select EMPLOYEES option from the name drop down. Select * from the columns check box. Click Next.
View ImageDescription of this image -
Click Test Query to verify the query's validity.
View ImageDescription of this image -
Observe the screen. The result of the query is shown. Click Finish.
View ImageDescription of this image -
We can organize the data to make it easier for the end user to consume, such as enabling pagination. Select the Enable Paging check box in the Grid View tasks.
View ImageDescription of this image
Executing the web site
In this section, you will run the ASP.NET web site and view the results returned from the Oracle database.
-
Select Build > Build Web Site.
View ImageDescription of this image -
Select Debug > Start Without Debugging.
View ImageDescription of this image -
Observe the output. The query results are displayed. Browse through the results using pagination. Close the application.
View ImageDescription of this image