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

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

 2007-05-13 12:30:03 来源:WEB开发网 闂傚倸鍊风欢姘缚瑜嶈灋闁圭虎鍠栫粻顖炴煥閻曞倹瀚�闂傚倸鍊风粈渚€骞夐敓鐘插瀭闁汇垹鐏氬畷鏌ユ煙閹殿喖顣奸柛搴$У閵囧嫰骞掗幋婵冨亾閻㈢ǹ纾婚柟鐐灱濡插牊绻涢崱妤冃℃繛宀婁簽缁辨捇宕掑鎵佹瀸闂佺懓鍤栭幏锟�濠电姷鏁告慨顓㈠箯閸愵喖宸濇い鎾寸箘閹规洟姊绘笟鈧ḿ褍煤閵堝悿娲Ω閳轰胶鍔﹀銈嗗笂閼冲爼鍩婇弴銏$厪闁搞儮鏅涙禒褏绱掓潏鈺佷槐闁轰焦鎹囬弫鎾绘晸閿燂拷闂傚倸鍊风欢姘缚瑜嶈灋闁圭虎鍠栫粻顖炴煥閻曞倹瀚�  闂傚倸鍊烽懗鑸电仚缂備胶绮〃鍛村煝瀹ュ鍗抽柕蹇曞У閻庮剟姊虹紒妯哄妞ゆ劗鍘ч埥澶娢熼柨瀣偓濠氭⒑瑜版帒浜伴柛鎾寸☉閳绘柨顫濋懜纰樻嫼闂佸憡绋戦オ鏉戔枔閺冣偓缁绘稓浠﹂崒姘瀳闂佸磭绮幑鍥嵁鐎n亖鏀介柟閭﹀墯椤斿倹淇婇悙顏勨偓鏍ь潖婵犳艾鍌ㄧ憸蹇涘箟閹绢喗鏅搁柨鐕傛嫹
核心提示: 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

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接