C # stored procedure parameter transfer method

Source: Internet
Author: User

In my original book, please indicate the source for loading

/// Author: ruva

// Emial: yiwenjun@126.com

//

/// Http://writeblog.csdn.net/PostEdit.aspx? Entryid = 4538458

 

The following describes how to transfer parameters in a stored procedure by inserting data in a database.

 

Stored Procedure database code

Alter procedure DBO. storedprocedure1 <br/> (<br/> @ username varchar (50), <br/> @ password varchar (50), <br/> @ email varchar (50) <br/>) <br/> as <br/> insert [user] (username, password, email) values (@ username, @ password, @ email)

 

C # PASS Parameters to a stored procedure and execute the Stored Procedure Code

Private void btnprocedurce_click (Object sender, eventargs e) <br/>{< br/> try <br/>{< br/> string username = txtusername. text; <br/> string Password = txtpassword. text; <br/> string email = txtemail. text; <br/> sqlparameter [] sp = new sqlparameter [] {New sqlparameter ("@ username", username), new sqlparameter ("@ password", password ), new sqlparameter ("@ email", email) }; <br/> sqlcommand cmd = new sqlcommand (); <br/> cmd. connection = conn; <br/> cmd. commandtype = commandtype. storedprocedure; <br/> cmd. commandtext = "storedprocedure1"; <br/> foreach (sqlparameter s in SP) <br/>{< br/> cmd. parameters. add (s); <br/>}< br/> cmd. executenonquery (); <br/>}< br/> catch (exception ex) <br/>{</P> <p> MessageBox. show (ex. stacktrace); <br/>}< br/>

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.