The release number of this article has been CHS309361
For Microsoft Visual Basic .NET versions of this article, see
308073.
For Microsoft Visual C .NET versions of this article, see
309362.
This article references the following Microsoft .NET Framework Class Bank Name Space:
System.Data.Oledb
This task content
summary
Create an Oracle table to create an Oracle package to create a Visual C # .NET application Other information
Summary This step-by-step guidance article
The DataReader object retrieves data from the Oracle stored procedure. you can use it
DataReader retrieves read-only, only forward data streams from the database. Because the memory is only retained in one line,
DataReader can improve the performance of the application and reduce system overhead.
Back to top
Require the following list lists the recommended hardware, software, network structure, and service pack required:
Microsoft Windows 2000 Professional, Windows 2000 Server, Windows 2000 Advanced Server or Windows NT 4.0 Server Microsoft Visual Studio .NET This article assumes that you are familiar with the following topics:
Visual C # .NET ADO.NET Basics and Syntax
Back to top
Creating an Oracle Table This example is used in a table defined in the Oracle Scott / Tiger architecture. The Oracle Scott / Tiger architecture is included in the default Oracle system.
If the schema does not exist, you must run the following table and insert the script of the table:
Create Table Dept
(Deptno Number (2,0) Not NULL,
DNAME VARCHAR2 (14) NULL,
Loc varchar2 (13) NULL,
PRIMARY Key (DePTNO)
);
INSERT INTO Dept Values (11, 'Sales', 'Texas');
INSERT INTO Dept Values (22, 'Accounting', 'Washington');
INSERT INTO Dept Values (33, 'Finance', 'MAINE');
CREATE TABLE EMP
(Empno Number (4,0) Not Null,
Ename varchar2 (10) NULL,
Job varchar2 (9) NULL,
Mgr Number (4,0) NULL,
Sal Number (7, 2) NULL,
Comm number (7,2) NULL,
DEPTNO NUMBER (2,0) NULL,
Foreign Key (Deptno) References Dept (DePTNO),
Primary Key (EMPNO)
);
INSERT INTO EMP VALUES (123, 'Bob ",' Sales', 555, 35000, 12, 11);
INSERT INTO EMP VALUES (321, 'Sue', 'Finance ", 555, 42000, 12, 33);
INSERT INTO EMP VALUES (234, 'Mary', 'Account ", 555, 33000, 12, 22);
Back to top
Create an Oracle package Create the following Oracle Packages on the Oracle Server:
Create Or Replace Package Curspkg_Join AS
TYPE T_CURSOR IS Ref Cursor;
Procedure open_join_cursor1 (n_empno in number, io_cursor in out t_cursor); End Curspkg_join;
/ Create the following Oracle package text on the Oracle server:
Create Or Replace Package Body Curspkg_Join AS
Procedure open_join_cursor1 (n_empno in number, io_cursor in out t_cursor)
IS
v_cursor t_cursor;
Begin
IF N_EMPNO <> 0
THEN
Open v_cursor for
Select Emp.empno, Emp.ename, Dept.deptno, Dept.dname
From EMP, DEPT
WHERE Emp.Deptno = Dept.deptno
And Emp.empno = N_EMPNO;
Else
Open v_cursor for
Select Emp.empno, Emp.ename, Dept.deptno, Dept.dname
From EMP, DEPT
WHERE Emp.Deptno = dept.deptno;
END IF;
IO_CURSOR: = V_Cursor;
End open_join_cursor1;
End curspkg_join;
/
Back to top
Create a Visual C # .NET application
Create a new Visual C # Windows application project. The Form1 is added to the project by default. Add the following code to the top of the "Code" window: use system.data.OLDB; add the following code to Form1 Form_Load Event: OLEDBConnection Oraclecon = New OLEDBCONNECTION ("provider = msdara.1; password = tiger;"
"User ID = Scott; Data Source = ORACLESERVER; PERSIST Security Info = true");
Oraclecon.open ();
OLEDBCommand mycmd = new oledbcommand
("{CALL CURSPKG_JOIN.OPEN_JOIN_CURSOR1 (?, {resultset 0, IO_CURSOR})}", Oraclecon);
Mycmd.parameters.add ("ID", OLEDBTYPE.NUMERIC, 4) .VALUE = 0;
OLEDBDATAREADER MyReader;
MyReader = mycmd.executeReader ();
INT X;
INT country;
count = 0;
While (MyReader.Read ())
{
For (x = 0; x <= myreader.fieldcount - 1; x )
Console.write (MyReader.getValue (x) ");
Console.writeLine ();
* Count = 1;
}
Messagebox.show (Count "Rows Returned.");
MyReader.Close ();
Oraclecon.close (); Modify the OLEDBConnection string accordingly according to your environment. Press F5 to compile and run the application. Note that data from the Oracle stored procedure appears in the Debug window and displays the number of rows in the message box. Back to top
Other information, the code passes
DataReader performs loop:
While (myReader.Read ()) because
DataReader only reads a line at a time.
Back to top
Refer to additional information, click the article number below to view the article in the Microsoft Knowledge Base:
176086 HOWTO: Using ADO from Oracle Store Retrieval Collection
For more information on DataReader, see the following topics in the Microsoft .NET Software Development Cap (SDK) document:
Use DataReader to retrieve data http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcontheaddDataReader.asp
Back to top
The information in this article applies to:
Microsoft ADO.NET (provided with .NET Frame) Microsoft Visual C # .NET (2002)
Reserved: 2002-6-18 (1.0) Keyword Kbdsupport KBGRPDSVBDB KBHOWTO KBHOWTOMASTER KBOLEDB KBSYSTEMDATA KB309361