c#调用oracle存储过程复习进程 下载本文

精品文档

using (OracleConnection connection = new OracleConnection(connectionString)) {

DataSet dataSet = new DataSet(); connection.Open();

OracleDataAdapter sqlDA = new OracleDataAdapter();

sqlDA.SelectCommand = BuildQueryCommand(connection, storedProcName, parameters ); sqlDA.Fill(dataSet, tableName ); connection.Close(); return dataSet; } }

///

/// 构建 OracleCommand 对象(用来返回一个结果集,而不是一个整数值) ///

/// /// /// /// OracleCommand

private static OracleCommand BuildQueryCommand(OracleConnection connection,string storedProcName, IDataParameter[] parameters) {

OracleCommand command = new OracleCommand(storedProcName, connection ); command.CommandType = CommandType.StoredProcedure; foreach (OracleParameter parameter in parameters) {

command.Parameters.Add( parameter ); }

return command; }

///

/// 执行存储过程,返回影响的行数 ///

收集于网络,如有侵权请联系管理员删除

精品文档

/// /// /// ///

public static int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected ) {

using (OracleConnection connection = new OracleConnection(connectionString)) { int result;

connection.Open();

OracleCommand command = BuildIntCommand(connection,storedProcName, parameters ); rowsAffected = command.ExecuteNonQuery();

result = (int)command.Parameters[\ //Connection.Close(); return result; } }

///

/// 创建 OracleCommand 对象实例(用来返回一个整数值) ///

/// /// /// OracleCommand 对象实例

private static OracleCommand BuildIntCommand(OracleConnection connection,string storedProcName, IDataParameter[] parameters) {

OracleCommand command = BuildQueryCommand(connection,storedProcName, parameters ); command.Parameters.Add( new OracleParameter ( \ OracleType.Int32,4,ParameterDirection.ReturnValue, false,0,0,string.Empty,DataRowVersion.Default,null )); return command; }

收集于网络,如有侵权请联系管理员删除

精品文档

#endregion

public DataSet GetCPResult(string s_aN_CPNO) {

OracleParameter[] parameter = {

new OracleParameter(\

new OracleParameter(\注意:这里参数名称前面都不能加\ new OracleParameter(\ parameter[0].Value = s_aN_CPNO; parameter[1].Value = \

parameter[2].Direction = System.Data.ParameterDirection.Output; return RunProcedure(\ }

收集于网络,如有侵权请联系管理员删除