The code for calling the Oracle stored procedure in C # looks like this:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Collections.ObjectModel;4 usingSystem.ComponentModel;5 usingSystem.Configuration;6 usingSystem.Data;7 usingSystem.Data.OracleClient;8 usingSystem.Drawing;9 usingSystem.Linq;Ten usingSystem.Reflection; One usingSystem.Text; A usingSystem.Threading.Tasks; - usingSystem.Windows.Forms; - the namespaceexecuteprocbyoracle - { - Public Partial classForm1:form - { + PublicForm1 () - { + InitializeComponent (); A } at - Private voidBtn_loaddata_click (Objectsender, EventArgs e) - { - //Stored Procedure name - stringstrProcName ="Usp_yngr_getinfectioncard"; - //Stored Procedure Parameters inoracleparameter[] Parameters = { - NewOracleParameter ("V_begintime", Oracletype.varchar), to NewOracleParameter ("V_endtime", Oracletype.varchar), + NewOracleParameter ("V_datetype", Oracletype.number), - NewOracleParameter ("V_ptname", Oracletype.varchar), the NewOracleParameter ("V_ptchartno", Oracletype.varchar), * NewOracleParameter ("V_deptcode", Oracletype.varchar), $ NewOracleParameter ("V_checkedstatus", Oracletype.varchar),Panax Notoginseng //the type of the return value is the cursor type - NewOracleParameter ("Cur_out", OracleType.Cursor) the }; + //set the value of the stored procedure parameter array and the type of the parameter Aparameters[0]. Value ="2017-06-01"; theparameters[0]. Direction =ParameterDirection.Input; +parameters[1]. Value ="2017-07-31"; -parameters[1]. Direction =ParameterDirection.Input; $parameters[2]. Value =1; $parameters[2]. Direction =ParameterDirection.Input; -parameters[3]. Value =""; -parameters[3]. Direction =ParameterDirection.Input; theparameters[4]. Value =""; -parameters[4]. Direction =ParameterDirection.Input;Wuyiparameters[5]. Value =""; theparameters[5]. Direction =ParameterDirection.Input; -parameters[6]. Value ="1"; Wuparameters[6]. Direction =ParameterDirection.Input; -parameters[7]. Direction =ParameterDirection.Output; About $ This. Dgv_demo.datasource =loaddata (strprocname, parameters); - } - - PrivateDataTable LoadData (stringstrProcName,paramsoracleparameter[] Parameters) A { + theDataTable dt =NewDataTable (); - stringstrconn = configurationmanager.connectionstrings["healthhospinfection"]. ConnectionString; $ using(OracleConnection conn =NewOracleConnection (strconn)) the { the Try the { the -OracleCommand cmd =NewOracleCommand (); inCmd.commandtext =strProcName; theCmd.commandtype =CommandType.StoredProcedure; theCmd. Connection =Conn; About Conn. Open (); the if(Parameters! =NULL) the { the //Adding Parameters + cmd. Parameters.addrange (Parameters); - } the Bayi //Fetch Data the using(OracleDataAdapter adapter =Neworacledataadapter (cmd)) the { - - adapter. Fill (DT); the } the } the Catch(Exception ex) the { -MessageBox.Show ("Error:"+ ex. Message +"/r/n Tracking:"+Ex. StackTrace); the } the finally the {94 Conn. Close (); the } the } the 98 returnDT; About } - }101}
Example code: Https://files.cnblogs.com/files/dotnet261010/CSharp%E6%89%A7%E8%A1%8COracle%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B.rar
C # calls Oracle stored Procedures