C # Call the mssql Stored Procedure Method

Source: Internet
Author: User
Tags oracleconnection

Asp tutorial. net c # Call the mssql Stored Procedure Method
In principle, as long as the program is dealing with SQL, it can call the mssql Stored Procedure. Below we provide two tutorial c # Call the mssql Stored Procedure Method

String constr = "data source = test; user id = scott; password = tiger ";
Oracleconnection con = new oracleconnection (constr );
Oraclecommand com = new oraclecommand ("sp2", con );
Com. commandtype = commandtype. storedprocedure;
Con. open ();
Oracleparameter p1 = new oracleparameter ("v_empno", oracletype. int32 );
Oracleparameter p2 = new oracleparameter ("v_sal", oracletype. double );
P1.direction = parameterdirection. input;
P1.value = 7369;
P2.direction = parameterdirection. output;
Com. parameters. add (p1 );
Com. parameters. add (p2 );
Com.exe cutenonquery ();
Textbox1.text = com. parameters ["v_sal"]. value. tostring ();
Con. close ();

Stored Procedure creation code

Create or replace procedure sp2 (v_empno number) is
V_sal number (7,2 );
Update emp set sal = sal + 200 where empno = v_empno;
Select sal into v_sal from emp where empno = v_empno;
Dbms_output.put_line ('employee ID: '| v_empno | 'salary:' | v_sal );


// Call method 2

Direction = parameterdirection. input;
Para. value = Name;
Sqlparameter para2 = new sqlparameter ("@ pwd", sqldbtype. char, 10 );
Para. direction = parameterdirection. input;
Para. value = password;
Sqlparameter para = new sqlparameter ("@ isvalid", sqldbtype. char, 10 );
Para. direction = parameterdirection. returnvalue;
Sqlcommand mycommand = new sqlcommand ("checkpass", conn)
Mycommand. commandtype = commandtype. storedprocedure;
Mycommand. parameters. add (para );
Mycommand. parameters. add (para2 );
Mycommand. excutenonquery ();
Bool isvalid = mycommand. parameters ["@ isvalid"]. value; // Return value

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: 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.