Asp.net calls the Stored Procedure

Source: Internet
Author: User

Stored Procedure

A query stored procedure.

Returns the queried records.

In. net, I receive this returned record set.

Answer:

(1) execute a stored procedure without Parameters CodeAs follows:

Sqlconnection conn = new sqlconnection ("connectionstring ");

Sqldataadapter da = new sqldataadapter ();

Da. selectcommand = new sqlcommand ();

Da. selectcommand. Connection = conn;

Da. selectcommand. commandtext = "nameofprocedure ";

Da. selectcommand. commandtype = commandtype. storedprocedure;

(2) The code for executing a stored procedure with parameters is as follows:

Sqlconnection conn = new sqlconnection ("connectionstring ");

Sqldataadapter da = new sqldataadapter ();

Da. selectcommand = new sqlcommand ();

Da. selectcommand. Connection = conn;

Da. selectcommand. commandtext = "nameofprocedure ";

Da. selectcommand. commandtype = commandtype. storedprocedure;

Param = new sqlparameter ("@ parametername", sqldbtype. datetime );

Param. Direction = parameterdirection. input;

Param. value = convert. todatetime (inputdate );

Da. selectcommand. Parameters. Add (PARAM );

To add output parameters:

Param = new sqlparameter ("@ parametername", sqldbtype. datetime );

Param. Direction = parameterdirection. output;

Param. value = convert. todatetime (inputdate );

Da. selectcommand. Parameters. Add (PARAM );

To obtain the return value of the parameter store process:

Param = new sqlparameter ("@ parametername", sqldbtype. datetime );

Param. Direction = parameterdirection. returnvalue;

Param. value = convert. todatetime (inputdate );

da. selectcommand. Parameters. Add (PARAM);

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.