In ASP. NET, how does one obtain parameters transmitted from stored procedures.

Source: Internet
Author: User

//-------------------------------------------------------------------------------
// 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! ");

Related Article

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.