1. Trang chủ
  2. » Công Nghệ Thông Tin

ODP .NET Developer''''s Guide oracle database 10g development with visual studio 2005 phần 9 pps

29 231 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 29
Dung lượng 1 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Introduction to Oracle Developer Tools for Visual In this chapter, we will mainly focus on the following: Features of Oracle Developer Tools for Visual Studio Creating and debugging PL/S

Trang 1

Chapter 8

[ 255 ]

Consuming the Web Service from ASP.NET

Now, we will develop an ASP.NET web application that consumes the web service developed previously The following are the steps:

1 Open Visual Studio 2005 environment

2 Create a new website by going to File | New | Web Site and provide the

information as shown in the following screenshot:

3 Using the Solution Explorer, right-click on the project and go to Add Web

Reference as follows:

Trang 2

Application Development Using ODP.NET

[ 256 ]

4 Browse the Web services on the local machine as shown below (if the web

service is available on your local machine)

5 Select the web service created earlier:

Trang 3

Chapter 8

[ 257 ]

6 Provide the Web reference name as EmpService and click on Add Reference:

7 Drag a GridView control and an ObjectDataSource control on to the web form and configure the data source of ObjectDataSource (using the smart

tag) as follows:

Trang 4

Application Development Using ODP.NET

[ 258 ]

8 Click Next and provide the SELECT method as getList() as follows:

9 Similarly, provide the UPDATE method as Update(), INSERT method as

Add(), DELETE method as Delete(), and finally click on and finally click on Finish.

Trang 5

Chapter 8

[ 259 ]

10 Using the smart tag of the GridView, configure its properties as follows:

11 Using the Properties window provide the DataKeyNames property of the

GridView as empno.

12 Press F5 to test and execute the application.

Developing Smart Device Applications

Microsoft Windows Mobile Platform is now fully supported with NET technology

We can develop and deploy NET-based applications directly on to smart devices enabled with Microsoft Windows Mobile operating system Before proceeding with developing smart device applications, let us discuss Microsoft Windows Mobile platform and the devices supporting it

Introducing Microsoft Windows Mobile

There exist several types of smart devices in the market including Smart Phones, Pocket PCs, Pocket PC Phones, Tablet PCs, etc Every smart device is installed with a mobile-based operating system with respect to the features of the device One of such operating systems is Microsoft Windows CE

Microsoft Windows CE is a small, embedded operating system (runs from ROM)

that has a look and feel similar to Microsoft Windows 95/98 It includes scaled down versions of Microsoft Excel, Microsoft Word, Microsoft Internet Explorer, etc

Trang 6

Application Development Using ODP.NET

[ 260 ]

Microsoft Windows Mobile (Windows Mobile in short) is a complete software

platform built on Windows CE Unlike Windows CE, the Windows Mobile for Smart Phone or Pocket PC operating systems is specifically designed for devices that require a specialized hardware configuration The software includes standardized interfaces and applications that ensure compatibility across hardware designs The Pocket PC is the best example device that gets equipped with Microsoft Windows Mobile operating system

The Pocket PC runs Windows CE as its core operating system Pocket PCs come with mobile versions of Microsoft Office applications in addition to Microsoft Outlook Mobile Though there are different Pocket PCs, many come with Wi-Fi to enable you to connect to the Internet when you are near to a wireless hotspot You can compose email messages and send them wirelessly or by synchronizing with your desktop computer

A Pocket PC Phone is a bit different from an ordinary Pocket PC You can do

everything with a Pocket PC Phone that you can do with a Pocket PC, but with the addition of cellular phone capabilities If you have a Pocket PC Phone, you can access the Internet through the GPRS service

A Smart Phone has phone capabilities and comes with a smaller set of applications Though you can add third-party software titles to your Smart Phone, the smaller keypad and screen are designed to give you quick one-handed access to important data A Smart Phone is a good choice for business users who need to check email, keep track of their calendars, and take voice notes

Microsoft.NET enables us to develop and deploy NET applications on Microsoft Windows Mobile-enabled smart devices like Smart Phones, Pocket PCs, Tablet PCs, etc To develop for either Smart Phones or Pocket PCs, we need not really buy those devices We simply need to have smart device client extensions installed as a part of Visual Studio 2005 (which automatically installs NET Compact Edition) When the extensions are installed, we are provided with few device emulators for developing and testing NET-based mobile applications However, for testing and production, it

is recommended to have physical smart devices

The next section focuses on developing a simple Pocket PC application, which

consumes the web service developed previously

Consuming a Web Service from Pocket PC

We have already developed a web service previously Now, let us make use of the same web service for the Pocket PC You need not have a physical Pocket PC in your hands to test it

Trang 7

Chapter 8

[ 261 ]

We can simply use existing emulators available as part of Visual Studio 2005 The following are the steps:

1 Open Visual Studio 2005 Environment

2 Go to File | New | Project.

3 Select and provide information as shown in the following figure:

4 Add a Web Reference for the web service you created earlier

Trang 8

Application Development Using ODP.NET

[ 262 ]

5 Drag and drop a DataGrid on to the Pocket PC emulator as shown below:

6 Modify the existing code as follows:

Public Class Form1

Private Sub Form1_Load(ByVal sender As

System.Object, ByVal e As System.EventArgs) Handles

Trang 11

Introduction to Oracle Developer Tools for Visual

In this chapter, we will mainly focus on the following:

Features of Oracle Developer Tools for Visual Studio

Creating and debugging PL/SQL stored procedures using Visual StudioDeveloping applications using the Automatic Code Generation feature of ODTDeveloping and deploying NET CLR stored procedures in Oracle database using Visual Studio

Features of Oracle Developer Tools

Oracle has released Oracle Developer Tools (ODT in short) for Visual Studio NET 2003/2005 to provide integrated support for developing NET applications that

access Oracle databases

When ODT gets installed, the most important feature we notice is the Oracle

Explorer (available through the View menu of Visual Studio.NET) It allows us to

browse existing Oracle objects (like tables, views, stored procedures, etc.), create or modify tables using table designer, view or edit data, execute SQL statements, etc

Trang 12

Introduction to Oracle Developer Tools for Visual Studio 2005

[ 266 ]

Some of the other major features are the following:

Designers and Wizards

Automatic Code Generation

PL/SQL Editor

Stored Procedure Testing

Oracle Data Window

SQL Query Window

Integrated Help System

In this section, we will have a glimpse at the most commonly used features along with sample screenshots

Before working with ODT, make sure that you configure your connection to connect to Oracle database using Oracle client

Connecting to Oracle from Visual Studio Using Oracle Explorer

Once ODT is installed on your system, you should be able to observe the Oracle

Explorer option in the View menu as follows:

Trang 13

Chapter 9

[ 267 ]

Oracle Explorer allows you to connect to and work with Oracle database from

within the Visual Studio environment It is very similar to Server Explorer (in Visual Studio) except that it works only with Oracle databases

Once you click on Oracle Explorer, you should be able to see the following:

Using the Oracle Explorer window, you can connect to Oracle database using Add

Connection as follows:

Once you are prompted with the Add Connection dialog box, you can provide your

own connection parameters similar to following:

Trang 14

Introduction to Oracle Developer Tools for Visual Studio 2005

[ 268 ] Once you hit Test connection, you should see the following message:

Trang 16

Introduction to Oracle Developer Tools for Visual Studio 2005

[ 270 ]

Retrieving Oracle Information from Visual Studio Using ODT

One of the easiest ways to retrieve Oracle table or column information is by using

Oracle Explorer together with the Properties window The moment we select a

database object, the details will be shown in the properties as follows:

Trang 17

Chapter 9

[ 271 ]

Similarly, when a column is selected, the details get pulled out as follows:

Trang 18

Introduction to Oracle Developer Tools for Visual Studio 2005

[ 272 ]

To retrieve all rows in a table, we can simply right-click on the table and select

Retrieve Data as follows:

That would automatically bring all the rows into the Visual Studio environment where we can view or modify the information as follows:

Trang 19

Chapter 9

[ 273 ]

If you would like to write your own query, execute it, and view the results, you can

use the Query Window option as follows:

Once the Query Window is opened, you can provide your own query and execute it

as follows:

Trang 20

Introduction to Oracle Developer Tools for Visual Studio 2005

Dealing with Tables, Views, and Sequences Using ODTYou can create a new table by right-clicking on Tables and selecting New Relational

Table as follows:

You can modify the existing table design by selecting Design as follows:

Once a table is opened in Design mode, you can modify all the information

(including columns, constrains, indexes, etc.) visually as follows:

Trang 21

Chapter 9

[ 275 ]

You can create or modify views in Oracle as follows:

Trang 22

Introduction to Oracle Developer Tools for Visual Studio 2005

Trang 23

Chapter 9

[ 277 ]

Very similar to sequences, we can even define synonyms with the following layout:

Another nice feature of ODT is the support for stored procedures, functions, and packages We can straight away create, modify, test, and execute these objects from within the Visual Studio Environment together with other features like IntelliSense, automatic script generation, etc

Creating Stored Procedures Using ODT

You can observe the following sequence of figures to create a stored procedure using ODT The following initiates the creation of a new PL/SQL stored procedure:

Trang 24

Introduction to Oracle Developer Tools for Visual Studio 2005

[ 278 ]

The following are the details of the stored procedure being created:

The moment Preview SQL is hit, you will observe the script generation as follows:

Trang 25

Chapter 9

[ 279 ]

The moment we save the stored procedure, the Visual Studio environment

automatically opens the stored procedure for editing (along with automatic code generation and IntelliSense support) as follows:

Debugging PL/SQL Stored Procedures from Visual Studio

ODT is tightly integrated with Visual Studio even to the level of debugging PL/SQL stored procedures Before using the PL/SQL debugging feature, we need to configure the database and Visual Studio environment to enable PL/SQL debugging Let us start configuring the database first

We need to provide a few privileges for user Scott, to allow him to debug PL/SQL stored procedures Once he is provided with the privileges, we will create a sample stored procedure and develop a small Windows (desktop) application, and finally debug the application together with a PL/SQL stored procedure

Trang 26

Introduction to Oracle Developer Tools for Visual Studio 2005

[ 280 ]

Log in with DBA privileges (or log in as SYSTEM user) and execute the following two commands:

SQL>grant debug any procedure to scott;

SQL>grant debug connect session to scott;

Open your Visual Studio IDE and create a new Windows Application project In

the Project properties of the application, make sure thatProject properties of the application, make sure that of the application, make sure that Enable the Visual Studio

hosting process is checked off (in the Debug tab) as follows This is required as the

debugging process crosses beyond the Visual Studio Debugger level

Trang 27

Chapter 9

[ 281 ]

Go to the Tools menu and switch on Oracle Application Debugging as follows:

Go to the Tools menu again and within the Options, switch on PL/SQL debugging

(of ODT) for all the necessary connections (you may have to connect to the database

using Oracle Explorer prior to doing this) as follows:

Trang 28

Introduction to Oracle Developer Tools for Visual Studio 2005

[ 282 ]

Develop a stored procedure in Oracle database (in SCOTT user) as follows:

CREATE OR REPLACE PROCEDURE p_emp_details(p_empno

emp.empno%TYPE, p_ename OUT emp.ename%TYPE,

p_AnnSal OUT NUMBER, p_deptno OUT emp.deptno%TYPE)AS

v_Sal emp.sal%TYPE;

v_AnnSal NUMBER(11,2);

BEGIN

SELECT ename, sal, deptno

INTO p_ename, v_Sal, p_deptno

'Employee not found');

WHEN TOO_MANY_ROWS THEN

/* this would not happen generally */

RAISE_APPLICATION_ERROR(-20002,

'More employees exist with the same number');

WHEN OTHERS THEN

RAISE_APPLICATION_ERROR(-20003, SQLERRM);

END;

Drag a button from the toolbox on to the Windows form, add reference to

stored procedure:

Imports Oracle.DataAccess.Client

Public Class Form1

Private Sub Button1_Click(ByVal sender As

System.Object, ByVal e As System.EventArgs) Handles

Trang 29

parameters (p_ename, p_AnnSal, andp_deptno) get filled with values, which are finally displayed using MsgBox.

Using the Oracle Explorer, right-click on P_EMP_DETAILS and click on Compile

Debug as follows:

Ngày đăng: 08/08/2014, 20:21

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN