Stored Procedure and C # Call

Source: Internet
Author: User

Create a table and prepare data.
-- Create Table
Create TableWhs_ry
(
NmVarchar2(10)Not Null,
ID Varchar2(10)Not Null,
Name Varchar2(20)Default'Not Null,
CompanyVarchar2(80)Default'Espur ',
ADDRVarchar2(80)Default& Apos; 00â · 224 ° ',
BirthdayVarchar2(8)Default'123 ',
ImageBlob
)
TablespaceUsers
Pctfree10
Initrans1
Maxtrans255
Storage
(
Initial64 K
Minextents1
Maxextents Unlimited
);
-- Add comments to the table
Comment On TableWhs_ry
Is'Whs ² â ~~±í ';

Create a package, which is used in the stored procedure. Declare it here.
Create Or Replace PackagePkg_whs_constAs
TypeRef_cursorIs Ref Cursor;
EndPkg_whs_const;

Create a stored procedure
Create Or Replace ProcedurePro_select_whs_ry (idstrIn String,
Out_curempOutPkg_whs_const.ref_cursor)As
Begin
OpenOut_curempFor
SelectNm, ID,Name, Company, ADDR, birthday, ImageFromWhs_ryWhereId = idstr;
EndPro_select_whs_ry;

Debug: Find pkg_whs_const in brows, right-click "test", enter the relevant parameters, and press f8. The result is displayed.

C # The stored procedure is not used properly.

 

Try

{

// Oledbconnection CNN = new oledbconnection ();

// CNN. connectionstring = "provider = msdaora.1; Password = aaaaaa; user id = lccrcc9999; Data Source = mybase; persist Security info = true ";

// CNN. open ();

// Oledbcommand comm = new oledbcommand ();

// Comm. commandtype = commandtype. storedprocedure;

// Comm. Parameters. Add ("idstr", oledbtype. varchar );

// Comm. Parameters. Add (oledbtype. cur );

Oracleconnection CNN = new oracleconnection ();

CNN. connectionstring = This. textbox1.text. Trim ();

CNN. open ();

MessageBox. Show ("success! ");

Oraclecommand cmd = new oraclecommand ();

Cmd. commandtext = "pro_select_whs_ry ";

Cmd. commandtype = commandtype. storedprocedure;

Cmd. Parameters. Add (New oracleparameter ("idstr", oracletype. Number). value = "0000000001 ";

Cmd. Parameters. Add (New oracleparameter ("out_curemp", oracletype. cursor). Direction = parameterdirection. output;

Cmd. Connection = CNN;

 

// Place the returned result set to Dataset

Dataset DS = new dataset ();

Oracledataadapter ADAP = new oracledataadapter ();

ADAP. selectcommand = cmd;

ADAP. Fill (DS );

This. gridcontrol1.datasource = Ds. Tables [0]. defaultview;

 

// Obtain the returned result set using oracledatareader

Oracledatareader RDR;

RDR = cmd. executereader ();

While (RDR. Read ())

{

// Process the read data.

}

RDR. Close ();

CNN. Close ();

}

Catch (exception ERR)

{

MessageBox. Show (ERR. Message );

}

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.