熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ADO.NET訪問Oracle 9i存儲過程(上)[8]

2022-06-13   來源: .NET編程 

  以下代碼執行該過程根據結果集創建 DataReader並將 DataReader 的內容輸出到控制台

 // create connection

  OracleConnection conn = new OracleConnection(Data Source=oracledb;

  User Id=UserID;Password=Password;);

  // create the command for the stored procedure

  OracleCommand cmd = new OracleCommand();

  cmdConnection = conn;

  cmdCommandText = SELECT_JOB_HISTORYGetJobHistoryByEmployeeId;

  cmdCommandType = CommandTypeStoredProcedure;

  // add the parameters for the stored procedure including the REF CURSOR

  // to retrieve the result set

  cmdParametersAdd(p_employee_id OracleTypeNumber)Value = ;

  cmdParametersAdd(cur_JobHistory OracleTypeCursor)Direction =

  ParameterDirectionOutput;

  // open the connection and create the DataReader

  connOpen();

  OracleDataReader dr = cmdExecuteReader();

  // output the results and close the connection

  while(drRead())

  {

  for(int i = ; i <drFieldCount; i++)

  ConsoleWrite(dr[i]ToString() + ;);

  ConsoleWriteLine();

  }

  connClose();

[]  []  []  []  []  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/15010.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.