Let everyone share C # call the Oracle stored procedure

xiaoxiao2021-03-06  55

Let everyone share C # call the Oracle stored procedure

Results of the

Oracle

1. Create Oracle Process Storage

Create or Replace Procedure Proce_Test (Paramin in Varchar2, Paramout Out var Varchar2) As Varparam Varchar2 (28); Begin Varparam: = paramin; paramout: = varparam || paraminout;

2. Test process storage

Declare param_out varchar2 (28); param_inout varchar2 (28); begin param_inout: = 'ff'; proce_test ('DD', param_out, param_inout); dbms_output.put_line (param_out);

Test results: DDFF

C # aspect

1. Create an interface

Type object name text attribute value Button Button1 call label label1 A: label label2 b: label m_input input Label M_INPUT_OUTPUT InputOutput Label

M_Print display: TextBox

m_txti

Textbox

m_txtio

2. Display code

(1) Reference Oracle components

Add Using System.Data.OracleClient in your code;

(2) Double-click the "call" button on the interface to prepare the following code:

Private void Button1_Click (Object Sender, System.Eventargs E)

{

String mconn = "data source = ora9i.ora.com; user id = ora; password = ora"; / / connection database

CONN = New OracleConnection (MCONN);

CMD = conn.createCommand ();

cmd.commandtext = "proce_test"; // Store process name

cmd.commandType = commandType.storedProcedure; // Declaration calling process

// The parameter of the stored procedure, parameters represents parameter name, oracletype.varchar represents parameter type, 20 represents the size of the parameters

OracleParameter Param_in = cmd.Parameters.Add ("paramin", oracletype.varchar, 20);

PARAM_IN.DIRECTION = parameterDirection.input; // Represents parameters storage method

PARAM_IN.VALUE = m_txti.text;

OracleParameter Param_out = cmd.Parameters.add ("paramout", ORACLETY.VARCHAR, 20);

Param_out.direction = parameterdirection.output;

OracleParameter Param_inout = cmd.Parameters.Add ("paraminout", ORACLETYPE.VARCHAR, 20);

PARAM_INOUT.DIRECTION = parameterDirection.inputoutput; param_inout.value = m_txtio.text;

Cn.open ();

// Perform a stored procedure

cmd.executenonquery ();

// Return to the value of the parameter

m_print.text = "Display:" param_out.value.toTOString ();

CONN.CLOSE ();

}

转载请注明原文地址:https://www.9cbs.com/read-114787.html

New Post(0)