C # Execution Oraclehelper

Source: Internet
Author: User
Tags oracleconnection

        /// <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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.