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

xiaoxiao2021-03-06  54

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

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 label3 Input Label Label4 InputputPut Label

Label5

Textbox

TextBox1

Textbox

Textbox2

2. Display code

(1) in the WebForm4.aspx.cs file

Add Field Private Oraoprater Mora = NULL; // Oraoprater is the class of data connection layer

Double-click the "Call" button on the interface to prepare 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 in the data connection layer (ORAOPRATER.CS)

Quote 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", ORACLETY.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

}

}

}

This code has passed, thank you for your visit.

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

New Post(0)