C # Call the SQL server stored procedure,

Source: Internet
Author: User

C # Call the SQL server stored procedure,

Go straight to the topic, record

  • Namespace: using System. Data. SqlClient;
  • Database LINK string: database link string format: server = {0}; database = {1}; uid = {2}; pwd = {3} // 0: server, 1: Database Name, 2: User Name, 3: Password
  • Call:
    Using (SqlConnection connection = new SqlConnection (SqlServerHelper. connectionString) {connection. open (); SqlCommand cmd = new SqlCommand ("Stored Procedure name", connection); cmd. parameters. add ("@ param1", SqlDbType. int); cmd. parameters ["@ param1"]. value = "param1_value"; cmd. parameters ["@ param1"]. direction = ParameterDirection. input; cmd. parameters. add ("@ param2", SqlDbType. int); cmd. parameters ["@ param2"]. value = "param2_value"; cmd. parameters ["@ param2"]. direction = ParameterDirection. input; // Outpu cmd. connection = connection; cmd. commandType = CommandType. storedProcedure; // The call type SqlDataReader dr = cmd. executeReader (); // executes the SQL statement and returns the result set // int rerows = cmd. executeNonQuery (); // execute the SQL statement, the number of affected rows while (dr. read () {// process the returned results // dr [0], dr ["col_name"]} dr. close (); // Close the execution of connection. close (); // Close the database}

     

 

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.