How do I invoke a stored procedure with parameters in C #?

Source: Internet
Author: User

1) The code for executing a stored procedure without 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;
(2) The code to execute 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);
If you need to add an output parameter:
param = new SqlParameter ("@ParameterName", sqldbtype.datetime);
Param. Direction = ParameterDirection.Output;
Param. Value = Convert.todatetime (inputdate);
DA.SELECTCOMMAND.PARAMETERS.ADD (param);
To get the return value of the stored procedure:
param = new SqlParameter ("@ParameterName", sqldbtype.datetime);
Param. Direction = ParameterDirection.ReturnValue;

How do I invoke a stored procedure with parameters in C #?

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.