How to write the call stored procedure code in .NET to the data connection layer

xiaoxiao2021-03-06  60

Oracle 1. Create an Oracle stored procedure create or replace procedure proce_test (paramin in varchar2, paramout out varchar2, paraminout in out varchar2) as varparam varchar2 (28); begin varparam: = paramin; paramout: = varparam || paraminout; end; 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 label3 Input Label Label4 InputputPut Label

Label5

Textbox

TextBox1

Textbox

Textbox2

2. Display code (1) Add field private oraopratern Mora = null; // ORAOPRATER is the class of data connection layer, and write the following code:

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

{

Mora = new oraoprater ();

Label5.text = Mora.Spexefor (TextBox1.text, TextBox2.text); // Method for calling the stored procedure

}

(2) Code (ORAOPRATER.CS) in the data connection layer references Oracle components

Using system;

Using system.data;

Using system.data.oraclient;

Namespace WebApplication4

{

Public Class Oraoprater

{

Private oracleConnection conn = null;

Private OracleCommand CMD = NULL;

Public oraoprater ()

{

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

CONN = New OracleConnection (MCONN);

Try

{

Cn.open ();

CMD = New OracleCommand ();

cmd.connection = conn;

}

Catch (Exception E)

{

Throw e;

}

}

Public String Spexefor (String M_a, String M_B)

{

// Parameter declaration of stored procedures OracleParameter [] parameters = {

New OracleParameter ("Paramin", ORACLETYPE.VARCHAR, 20),

New OracleParameter ("Paramout", ORACletype.varchar, 20), New OracleParameter ("paraminout", ORACletype.varchar, 20)

}

Parameters [0] .value = m_a;

Parameters [2] .value = m_b;

Parameters [0] .direction = parameterdirection.input;

Parameters [1] .direction = parameterDirection.output;

Parameters [2] .direction = parameterDirection.inputout;

Try

{

Runprocedure ("proce_test", parameters);

Return parameters [1] .value.toString ();

}

Catch (Exception E)

{

Throw e;

}

}

Private void Runprocedure (String StoredProcname, OracleParameter [] Parameters)

{

cmd.commandtext = storedProcName; // Declaration Storage Procedure Name

cmd.commandtype = commandtype.storedProcedure;

Foreach (OracleParameter Parameter in Parameters)

{

Cmd.Parameters.Add (parameter);

}

cmd.executenonQuery (); // Execute a stored procedure

}

}

} Transferred from: http://blog.9cbs.net/surpriseruck/archive/2004/09/22/113024.aspx? Pending = TRUE

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

New Post(0)