WEB开发网
开发学院数据库Oracle 使用ADO.NET访问Oracle 9i存储过程(下) 阅读

使用ADO.NET访问Oracle 9i存储过程(下)

 2007-05-13 12:30:03 来源:WEB开发网   
核心提示: Rows affected: 1Location ID: 3300使用 DataAdapter 填充数据集可使用 REF CURSOR 通过 DataAdapter 来填充 DataSet,下面的代码利用了使用 DataReader 一节中定义的存储过程 GetJobHistoryByEm

Rows affected: 1

Location ID: 3300

使用 DataAdapter 填充数据集

可使用 REF CURSOR 通过 DataAdapter 来填充 DataSet。下面的代码利用了使用 DataReader 一节中定义的存储过程 GetJobHistoryByEmployeeId,并用它在 REF CURSOR 输出参数中返回的结果集来填充 DataSet。

以下是使用 DataAdapter 填充 DataSet 的代码:

// create the connection
OracleConnection conn = new OracleConnection("Data Source=oracledb;
  User Id=UserID;Password=Password;");
// create the command for the stored procedure
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT_JOB_HISTORY.GetJobHistoryByEmployeeId";
cmd.CommandType = CommandType.StoredProcedure;
// add the parameters for the stored procedure including the REF CURSOR
// to retrieve the result set
cmd.Parameters.Add("p_employee_id", OracleType.Number).Value = 101;
cmd.Parameters.Add("cur_JobHistory", OracleType.Cursor).Direction =
  ParameterDirection.Output;
// createt the DataAdapter from the command and use it to fill the
// DataSet
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
// output the results.
Console.WriteLine(ds.Tables[0].Rows.Count);

对于 HR 架构的默认安装,输出表明员工 101 有两个 JOB_HISTORY 记录。

上一页  1 2 3 4 5 6 7  下一页

Tags:使用 ADO NET

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接