View Products Sample - Populate DataSet With Multiple REF Cursors Through ODP.NET

Table of Contents

Objective of the Sample Application

Back To Top

The purpose of this sample application is to demonstrate how to populate a DataSet with data from multiple REF Cursors through Oracle Data Provider for .NET (ODP.NET) using C#.

Overview of the Sample Application

Back To Top

The database Stored Procedure returning multiple REF Cursors is called using OracleCommand Object. The REF Cursor parameters are bound to OracleCommand object using 'OracleDbType.RefCursor'. The Command type is set to 'StoredProcedure' for OracleCommand. The OracleDataAdapter executes this command object. OracleDataAdapter fills the DataSet with REF Cursors returned from the Stored Procedure. The No. of Data Tables created in the DataSet is equal to the No. of REF Cursors returned from the Stored Procedure. The Data Tables are named as 'TableN' where N stands for an integer starting from 0. These Data Tables can be bound to different Data Grids. 

When this sample application is run, two Data Grids are displayed. One Data Grid populated with records for products with 'Orderable' product status and other Data Grid populated with records for products with 'Under Development' product status. A database Stored Procedure 'GetProductsInfo' is called that returns two REF cursors as 'OUT' parameters. The DataSet is filled with data in REF Cursor. The two Data Tables created are 'Products' and 'Products1'. The Data Grids are bound to these Data Tables. This demonstrates how to populate DataSet with multiple REF Cursors. 

User Notes with Screen Shots

Back To Top

When this sample application is run, a list of products with 'Orderable' status is shown in the first Data Grid and a list of products with 'Under Development' status in the second Data Grid is displayed as shown in figure 1.1,  On clicking the 'Close' button, the application gets closed. 


  Figure 1.1 Screen Shot for Populate Data Set with Multiple REF Cursors Sample

Required Software

Back To Top
  • Visual C# installed with MS Development Environment 7.0 version (MS Visual Studio .NET)  including MS .NET Framework 1.0 version  

  • Oracle8i Database or later running SQL*Net TCP/IP listener (can be downloaded here )

  • Oracle Data Provider for .NET (ODP.NET) (can be downloaded here )

Extracting the Sample

Back To Top

Unzip DSwithRefCur.zip using Winzip or command utility to your convenient directory referred to as <Extract_Dir>. Extraction of the zip file results in the creation of 'DSwithRefCur' directory.  Refer Description of Sample Files section for more details.     

Database Setup

Back To Top

Connect to your database as any user and run the scripts DSwithRefCur\Setup\DatabaseSetup.sql and  DSRefCur\Config\StoredProcedure.sql at the SQL prompt
SQL> @<Extract_Dir>\DSwithRefCur\Setup\DatabaseSetup.sql
SQL> @<Extract_Dir>\DSwithRefCur\Setup\StoredProcedure.sql

DatabaseSetup.sql file creates a user "OraNet" with password "OraNet". This script prompts for "SystemPassword" and "TNSName". All the database objects required by the application are created and populated with sample data. StoredProcedure.sql file creates a package 'ODPNet' that returns multiple REF Cursors. 

Following is the list of database objects that get created by running DatabaseSetup.sql file.
Object Name Description
Products Table that store information about products.
Printmedia Table that stores information about the advertisement related to products.
Adid_seq Sequence for auto generating Advertisement ID.
Populate_AdID Trigger for populating  Ad_ID column of 'PrintMedia'  table on insertion.
ODPNet Database Package containing 'getProductsInfo' stored procedure.

 

Preparing and Running the Sample

Back To Top

1. Ensure that the Database setup has been completed. 

2. Open DSwithRefCur.sln using Visual Studio .NET from <Extract_Dir>\DSwithRefCur folder. 

3. Edit ConnectionParams.cs file to change the database connection parameters i.e.TNSName for  database 
you want to use . Save this file. 

4. Ensure that the following .NET Component References have been added to DSwithRefCur project: 
          System, 
          System.Data, 
          System.Drawing, 
          System.Windows.Forms, 
          System.XML,
          Oracle.DataAccess. 

To add the above .NET Components 
a)Go to Menu ->View-> Solution Explorer. 
b)Right click on DSwithRefCur project, choose 'Add Reference'. 
c)Choose the above .NET Components from the list displayed. 
d)Click 'Select', then OK. 
e) The chosen .NET component gets added to the project. 

5. Build and run the sample.

Description of Sample Files

Back To Top

Following is the directory structure of the DSwithRefCur.zip :

Directory File Name Description
DSwithRefCur\doc Readme.html This file
otn.css This is a cascading stylesheet applied to Readme.html
DSwithRefCur\doc\images This folder contains images used in the Readme.html file
DSwithRefCur\src ConnectionParams.cs This C# file contains parameters for database connection
ViewProducts.cs This C# file contains source code for UI for this sample application and its functionality
DSwithRefCur.csproj C# project file
ViewProducts.resx .NET XML Resource Template (this file gets automatically generated when a Visual Studio Project is created)
DSwithRefCur.sln Microsoft Visual Studio Solution
DSwithRefCur\Setup DatabaseSetup.sql This is a SQL script file that creates tables and populate them with sample data.
StoredProcedure.sql This is a SQL file that creates 'ODPNet' Package