Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > VB.NET > Retrieve multiple Oracle Ref Cursor using .NET data Provider for Oracle
【标  题】:Retrieve multiple Oracle Ref Cursor using .NET data Provider for Oracle
【关键字】:Retrieve,multiple,Oracle,Ref,Cursor,using,.NET,data,Provider,for,Oracle
【来  源】:http://attraction.cnblogs.com/archive/2004/06/05/13665.html

Retrieve multiple Oracle Ref Cursor using .NET data Provider for Oracle

Your Ad Here
Introduction
In my earlier article Multiple Result Sets in ADO.net using SqlClient ,we have seen how to retrieve multiple results using Sqlclient against SQL Server. This was a fairly simple and straight forward. We can achieve the same against Oracle database with a slight difference. We need to iron out couple of things before we get to nuts and bolts of it.

  • We need System.Data.OracleClient.Dll assembly that is very similar to System.Data.SqlClient.Dll,.NET Managed Provider forOracle is not a part of .NET Version 1.0, a separate download click here to download . For .NET version 1.1, it’s going to be part of the bundle. If you are new to .Net framework provider for Oracle read my articles on code101 Boost performance with .net data provider for oracle
  • We need a stored procedure to return multiple results set using REF CURSOR. For novice, A ref cursor is a PL/SQL data type that you can use in a query to fetch data. Each ref cursor query is associated with a PL/SQL function that returns a strongly typed ref cursor.
Lets get feet dirty
Create a oracle package, I assume you know what a package by the way it has two parts Specification and body
Package Specification
CREATE OR REPLACE PACKAGE PKG_MUltiResultset as
 TYPE MyRefCur is REF CURSOR;
 procedure GetReadOnlyData(EmpCur OUT MyRefCur,
			  DeptCur OUT MyRefCur,
			  SalCur OUT MyRefCur);
END;
Package body
CREATE OR REPLACE PACKAGE BODY PKG_MUltiResultset as
  PROCEDURE GetReadOnlyData(EmpCur OUT MyRefCur,
	   		   DeptCur OUT MyRefCur,
			   SalCur OUT MyRefCur)
  IS
  BEGIN 
    open EmpCur for select * from emp;
    open DeptCur for select * from dept;
    open SalCur for select * from salgrade;
  END;
 END;
Lets us get to the client part to access this stored procedure. We will establish connection to Oracle database retrieve data from three tables in one shot and fill up the dataset and bind the data to DataGrids.I am using Dataset you can try it with OracleDataReader as well.
NOTE: The Prefix is always Oracle for all the classes in Syatem.Data.OracleClient name space. Reference name spaces
using System.Data.OracleClient;
using System.Data;
 Private void GetData_Click(object sender, System.EventArgs e)
  {
    try
      {
	//Connect to Database
	OracleConnection oCon=new OracleConnection
        ("Data source=Firstdb;user id=scott;password=tiger");
	 oCon.Open();
	
        //Command Object
	OracleCommand oCmd =new OracleCommand
        ("PKG_MUltiResultset.GetReadOnlyData",oCon);

	//Stored Procedure
	oCmd.CommandType=CommandType.StoredProcedure;

	//Create Parameter Object
        oCmd.Parameters.Add(new OracleParameter
        ("empcur",OracleType.Cursor)).Direction=ParameterDirection.Output;
     
        oCmd.Parameters.Add(new OracleParameter
        ("DeptCur",OracleType.Cursor)).Direction=ParameterDirection.Output;
     
        oCmd.Parameters.Add(new OracleParameter
       ("SalCur",OracleType.Cursor)).Direction=ParameterDirection.Output;
	
	//Instatiate Dataset
	DataSet Ds=new DataSet();

	//Instatiate Data Adopter
	OracleDataAdapter oAdp=new OracleDataAdapter(oCmd);

	//Fill Data Set
	oAdp.Fill(Ds);

	//Bind Data to Grids
	dataGrid1.SetDataBinding(Ds,"Table");
	dataGrid2.SetDataBinding(Ds,"Table1");
	dataGrid3.SetDataBinding(Ds,"Table2");
	}
  	 catch (Exception x)
	{
	 MessageBox.Show(x.Message);
	}
      }
VS2005來了,你準備好了嗎?:【上一篇】
oracle的存储过程如何返回结果集:【下一篇】
【相关文章】
  • 面对Oracle 选择 OracleClient 还是 Oledb??
  • 提醒各位! 安装了.Net Framework 1.1 SP1 后的问题!!
  • 如何检验计算机已经安装了.Net FrameWork
  • Using NAnt to Build .NET Projects
  • Microsoft Office InfoPath 2003 Toolkit for Visual Studio .NET
  • Test Your Knowledge of Microsoft Visual Studio .NET
  • vs.net2003无法打开*.xsd文件的解决方法
  • asp.net在2003和xp下的不同执行结果。
  • 被.net郁闷的一天
  • vb.net和C#开发环境和开发效率的比较
  • 【随机文章】
  • 如何防止黑客的攻击
  • 补充:用Ms SQL Server 存储过程操作DBF文件
  • 面向对象是什么
  • jetty与maven集成
  • OBP簡介_01
  • 后门技术和Linux LKM Rootkit
  • NAT HOWTO 简体中文版
  • mssqlser下的另类分页实现
  • 系统风险与入侵检测(2)
  • Class文件详解 (2)
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.