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

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 through Oracle Data Provider for .NET (ODP.NET) using C#.

Overview of the Sample Application

Back To Top

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). 

User Notes with Screen Shots

Back To Top

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 

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 DSPopulate.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 'DSPopulate' 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 script <Extract_Dir>\DSPopulate\Setup\DatabaseSetup.sql at the SQL prompt
SQL> @<Extract_Dir>\DSPopulate\Setup\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.

 

Preparing and Running the Sample

Back To Top

1. Ensure that the Database setup has been completed. 

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

3. Edit ConnectionParams.cs file to change the database connection parameters i.e.Username, Password, TNSName for  database  .You need to input the same values of connection parameters as given while doing the Database Setup. Save this file.

4. 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 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. 

5. Build and run the sample.

Description of Sample Files

Back To Top

Following is the directory structure of the DSPopulate.zip :

Directory File Name Description
DSPopulate\doc Readme.html This file
otn.css This is a cascading stylesheet applied to Readme.html
DSPopulate\doc\images *.gif This folder contains images used in the Readme.html file
DSPopulate\src 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
ViewProducts.resx .NET XML Resource Template (this file gets automatically generated when a Visual Studio Project is created)
DSPopulate.sln Visual Studio Solution
DSPopulate\Setup DatabaseSetup.sql This is a SQL script file