//-------------------------------------------------------------------------------
// Obtain the output parameters of the stored procedure.
// Oledb method, tested
//-------------------------------------------------------------------------------
Oledbcommand mycommand = new oledbcommand ();
Mycommand. Connection = cn;
If (CN. State = connectionstate. Closed ){
CN. open ();
}
Mycommand. commandtext = "show1_test ";
Mycommand. commandtype = system. Data. commandtype. storedprocedure;
Mycommand. commandtimeout = 20;
Oledbparameter inpara = new oledbparameter ("@ ina", oledbtype. varchar, 80 );
Inpara. value = "5 ";
Inpara. Direction = parameterdirection. input;
Mycommand. Parameters. Add (inpara );
Oledbparameter outpara = new oledbparameter ("@ outb", oledbtype. varchar, 80 );
Outpara. Direction = parameterdirection. output;
Mycommand. Parameters. Add (outpara );
Mycommand. executenonquery ();
Response. Write (outpara. value );
Oledbdatareader myreader = mycommand. executereader ();
Datatable dt = new datatable ();
DT. Columns. Add ("subjectname ");
DT. Columns. Add ("createdate ");
While (myreader. Read ())
{
Datarow workrow = DT. newrow ();
Workrow ["subjectname"] = myreader. getvalue (1 );
Workrow ["createdate"] = myreader. getvalue (2 );
DT. Rows. Add (workrow );
// Response. Write (myreader. getvalue (0). tostring () + "<br> ");
}
Myreader. Close ();
// Bindgrid ();
Mydatagrid. datasource = DT. defaultview; // myreader;
Mydatagrid. databind ();
// ---------------------------------------------------------------------------------
// test the parameter obtained from the stored procedure.
// sqlclient Mode, test passed
// connect to the database
sqlconnection sqlconn = new sqlconnection ();
sqlconn. connectionstring = "Server = 192.168.3.80; uid = sa; Password = rain; database = mystudy";
// server = 192.168.3.80; uid = sa; Password = rain; database = mystudy ";
sqlconn. open ();
sqlcommand COM = new sqlcommand ();
COM. connection = sqlconn;
Com. commandtext = "show1_test ";
Com. commandtype = commandtype. storedprocedure;
Sqlparameter [] p_htno = new sqlparameter [2];
P_htno [0] = new sqlparameter ("@ ina", sqldbtype. varchar, 80 );
P_htno [1] = new sqlparameter ("@ outb", sqldbtype. varchar, 80 );
P_htno [0]. value = "test input ";
P_htno [1]. Direction = parameterdirection. output;
// P_htno [1]. value = This. drop_character.items [This. drop_character.selectedindex]. value;
For (INT I = 0; I <p_htno.length; I ++)
{
Com. Parameters. Add (p_htno [I]);
}
Com. executenonquery ();
Response. Write (p_htno [1]. value. tostring () + "<br> the test output is successful! ");