/// <summary> ///execute stored procedure to get parameters with out/// </summary> /// <param name= "Cmdtext" >Stored Procedure name</param> /// <param name= "Outparameters" >parameter name of the output</param> /// <param name= "Oracleparameters" >parameters passed (must follow stored procedure parameter order)</param> /// <param name= "strconn" >Link String</param> /// <returns></returns> Public Static stringExectostoredproceduregetstring (stringCmdtext,stringOutparameters, oracleparameter[] oracleparameters,stringstrconn) { using(OracleConnection conn =NewOracleConnection (strconn)) { //oracleparameter[] SqlParameters = {//New OracleParameter ("ZYH", Oracledbtype.varchar2, "", ParameterDirection.Input),//New OracleParameter ("Yjje", oracledbtype.varchar2,100, "", ParameterDirection.Output)//};OracleCommand cmd =NewOracleCommand (CMDTEXT, conn); Cmd.commandtype=CommandType.StoredProcedure; Cmd. Parameters.addrange (oracleparameters); Conn. Open (); Cmd. ExecuteNonQuery (); Conn. Close (); returncmd. Parameters[outparameters]. Value.tostring (); } } /// <summary> ///Execute stored procedure get cursor data set with out/// </summary> /// <param name= "Cmdtext" >Stored Procedure name</param> /// <param name= "Outparameters" >cursor name of the output</param> /// <param name= "Oracleparameters" >parameters passed (must follow stored procedure parameter order)</param> /// <param name= "strconn" >Link String</param> /// <returns></returns> Public StaticDataTable exectostoredproceduregettable (stringStoredprocedname, oracleparameter[] oracleparameters,stringstrconn) { using(OracleConnection conn =NewOracleConnection (strconn)) {OracleCommand cmd=NewOracleCommand (STOREDPROCEDNAME, conn); Cmd.commandtype=CommandType.StoredProcedure; Cmd. Parameters.addrange (oracleparameters); OracleDataAdapter ODA=NewOracleDataAdapter (CMD); Conn. Open (); DataSet DS=NewDataSet (); Oda. Fill (DS); Conn. Close (); returnDs. tables[0]; } } /// <summary> ///execution stored procedure does not return a value/// </summary> /// <param name= "Cmdtext" >Stored Procedure name</param> /// <param name= "Outparameters" >Parameters</param> /// <param name= "Oracleparameters" >parameters passed (must follow stored procedure parameter order)</param> /// <param name= "strconn" >Link String</param> /// <returns></returns> Public Static voidExectostoredprocedure (stringCmdtext, oracleparameter[] oracleparameters,stringstrconn) { using(OracleConnection conn =NewOracleConnection (strconn)) {OracleCommand cmd=NewOracleCommand (CMDTEXT, conn); Cmd.commandtype=CommandType.StoredProcedure; Cmd. Parameters.addrange (oracleparameters); Conn. Open (); Cmd. ExecuteNonQuery (); Conn. Close (); } } /// <summary> ///Execute SQL Get data set/// </summary> /// <param name= "Cmdtext" >SQL statements</param> /// <param name= "Oracleparameters" >parameters passed (must follow stored procedure parameter order)</param> /// <param name= "strconn" >Link String</param> /// <returns></returns> Public StaticDataTable exectosqlgettable (stringCmdtext, oracleparameter[] oracleparameters,stringstrconn) { using(OracleConnection conn =NewOracleConnection (strconn)) {OracleCommand cmd=NewOracleCommand (CMDTEXT, conn); Cmd.commandtype=CommandType.Text; Cmd. Parameters.addrange (oracleparameters); OracleDataAdapter ODA=NewOracleDataAdapter (CMD); Conn. Open (); DataSet DS=NewDataSet (); Oda. Fill (DS); Conn. Close (); returnDs. tables[0]; } } /// <summary> ///Execute SQL Get data set/// </summary> /// <param name= "Cmdtext" >SQL statements</param> /// <param name= "Oracleparameters" >parameters passed (must follow stored procedure parameter order)</param> /// <param name= "strconn" >Link String</param> /// <returns></returns> Public StaticDataTable exectosqlgettable (stringCmdtext,stringstrconn) { using(OracleConnection conn =NewOracleConnection (strconn)) {OracleCommand cmd=NewOracleCommand (CMDTEXT, conn); Cmd.commandtype=CommandType.Text; OracleDataAdapter ODA=NewOracleDataAdapter (CMD); Conn. Open (); DataSet DS=NewDataSet (); Oda. Fill (DS); Conn. Close (); returnDs. tables[0]; } } /// <summary> ///perform SQL execution additions and deletions/// </summary> /// <param name= "Cmdtext" >SQL statements</param> /// <param name= "Oracleparameters" >parameters passed (must follow stored procedure parameter order)</param> /// <param name= "strconn" >Link String</param> /// <returns></returns> Public Static intExectosqlnonquery (stringCmdtext, oracleparameter[] oracleparameters,stringstrconn) { using(OracleConnection conn =NewOracleConnection (strconn)) {OracleCommand cmd=NewOracleCommand (CMDTEXT, conn); Cmd.commandtype=CommandType.Text; Cmd. Parameters.addrange (oracleparameters); Conn. Open (); intresult =cmd. ExecuteNonQuery (); Conn. Close (); returnresult; } } /// <summary> ///perform SQL execution additions and deletions/// </summary> /// <param name= "Cmdtext" >SQL statements</param> /// <param name= "Oracleparameters" >parameters passed (must follow stored procedure parameter order)</param> /// <param name= "strconn" >Link String</param> /// <returns></returns> Public Static intExectosqlnonquery (stringCmdtext,stringstrconn) { using(OracleConnection conn =NewOracleConnection (strconn)) {OracleCommand cmd=NewOracleCommand (CMDTEXT, conn); Cmd.commandtype=CommandType.Text; Conn. Open (); intresult =cmd. ExecuteNonQuery (); Conn. Close (); returnresult; } }
<summary>////Execute multiple SQL Get return value///</summary>//<param name= "Listselectsql" ></ param>//<returns></returns> public DataSet Query (list<string> listselectsql,string strconn) {using (OracleConnection conn = new OracleConnection (strconn )) {OracleCommand cmd = new OracleCommand (); StringBuilder strSQL = new StringBuilder (); Strsql.append ("Begin" ); for (int i = 0; i < Listselectsql.count; i++ ) {string paraname = "P_cursor_" + i; Strsql.appendformat ("Ope N: {0} for {1}; ", Paraname, Listselectsql[i]); Cmd. Parameters.Add (Paraname, Oracledbtype.refcursor, DBNull.Value, ParameterDirection.Output); } strsql.append ("END;" ); Cmd. Connection = conn; cmd.commandtext = strsql.tostring (); OracleDataAdapter ODA = new oracledataadapter (); Oda. SelectCommand = cmd; conn. Open (); DataSet ds = new DataSet (); Oda. Fill (DS); Conn. Close (); Return ds;}
C # Execution Oraclehelper