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 );
}