View Products Sample - Populate Dataset through ODP.NET using C# View Products Sample - Populate Dataset through ODP.NET using C#


Date: 11-Sep-2002


Table of Contents

Introduction
Application Overview
Software Requirements
Terminology
Configuring the Application
Deploying and Running the Application
Sample Application Files

Introduction

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

Prerequisite

To understand this sample, you need to have working knowledge of .NET, ODP.NET and Oracle Database.

Technical Overview

ODP.NET offers faster and reliable access to Oracle Database by using Oracle Native APIs. ODP.NET provides features to access any .NET application. The data access through ODP.NET can be done using a collection of classes contained in Oracle.DataAccess assembly. Figure 1.1 describes how data is accessed using ODP.NET.


Figure 1.1 Data Access Using ODP.NET

DataSet is a major component of ADO .NET. It is an in-memory cache of the data retrieved from the database. OracleDataAdapter represents a set of data commands and a database connection that are used to fill the DataSet based on the query given. OracleCommand represents SQL statements to execute against datasource. OracleConnection is used to build the database connection.

This C# sample application displays a product catalog for a product store. When this sample is run, a list of products from database appears in a DataGrid (in tabular format). The DataGrid gets populated from a DataSet which is filled by a DataSource using OracleDataAdapter. This demonstrates how to populate DataSet through Oracle Data Provider for .NET (ODP.NET).

Application Overview

When this sample application is run, a list of Products from database is displayed as shown in figure 1.2, on clicking the 'Close' button, the application gets closed.



Figure 1.2: Screen Shot for DataSet Populate Sample

Software Requirements

List the softwares required for configuring and running this sample application.

Terminology

Term Definition
The directory where the sample is extracted

Configuring the Application

1. Unzip DSPopulate.zip using Winzip or command utility to your convenient directory referred to as <SAMPLE_HOME>. Extraction of the zip file results in the creation of 'DSPopulate' directory. Refer description of Sample Application Files section for more details.


2. Connect to your database as any user and run the script \DSPopulate\Config\DatabaseSetup.sql at the SQL prompt

SQL> @\DSPopulate\Config\DatabaseSetup.sql

This script will prompt for the username, password and connectstring. You may choose any existing username. Products table will get created in specified users schema.

Deploying and Running the Application

The application can be deployed and run in the following way:

1. Ensure that the database setup has been completed.

2. Open DSPopulate.sln using Visual Studio .NET from <SAMPLE_HOME>\DSPopulate folder.

3. Ensure that the following .NET Component References have been added to DSPopulate project

System
System.Data
System.Drawing
System.Windows.Forms
System.XML
Oracle.DataAccess

To add the reference to above .NET Components

a)Go to Menu ->View-> Solution Explorer.
b)Right click on DSPopulate 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.
4. Edit ConnectionParams.cs file to change the database connection parameters i.e.Username, Password, TNSName for database and save this file. You need to input the same values of connection parameters as given while doing the Database Setup.

5. Build and run the sample.

Sample Application Files 

Following is the directory structure of the DSPopulate.zip :

Directory File Description
Readme.html

This file

otn_new.css
Stylesheet used in Readme.html
*.gif

This folder contains images used in the Readme.html file

DSPopulate.sln
Visual Studio Solution
DSPopulate.suo
Solution User option (this file gets automatically generated when a Visual Studio Solution is created)
ConnectionParams.cs
This C# file contains parameters for database connection
ViewProducts.cs
This C# file contains source code for UI for sample application and its functionality
DSPopulate.csproj
C# project file
DSPopulate.csproj.user
Visual Studio Project User Options (this file gets automatically generated when a Visual Studio Project is created)
ViewProducts.resx
.NET XML Resource Template (this file gets automatically generated when a Visual Studio Project is created)
DatabaseSetup.sql
This is a SQL script file


Please enter your comments about this sample application here.

 

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