Returned values of output type and return type in Stored Procedures

Source: Internet
Author: User
Tags rowcount

When I was working on a system with a teacher some time ago, when I wrote a stored procedure under MSSQL, I encountered the problem of output-type return values and return-type return values;
After some attempts, I understand it. I 'd like to share it with you;
Return is a custom keyword returned by MSSQL. Its usage is relatively simple.
Eg
Select * from student where Dep = @ Dep
Return @ rowcount
Return @ rowcount returns the number of affected rows,
In sqlhelper, you can use cmd. Parameters ["returnvalue"]. Value to obtain the return value.
However, if the output-type return value also uses the returnvalue to return the value, an exception occurs,
Eg
Create procedure sp_higheducation_articlerole_getcredbycondition
@ Categoryid nvarchar (16 ),
@ Authorplace nvarchar (16 ),
@ Grade int output
As
Select @ grade = getcred from articlerole where categoryid = @ categoryid and authorplace = @ authorplace
Go
In sqlhelper
If (CMD. Parameters [Grade]. value. tostring () = "")
{
Return 0;
}
Else
{
Return Int. parse (CMD. Parameters [Grade]. value. tostring ());
}
Of course, this is an output-type return value. For Multiple Output-type return values, it should be filled in DS and DT.

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.